views:

753

answers:

2

I need to use a binary data in a transformation as an integer and do some manipulation, but how to do the casting? I tried many SSIS data types but no luck. By the way I do not want to use script task.


[Updated section below]

The data is the values stored in the __$update_mask column of the CDC function fn_cdc_get_net_changes. Following is the CAST I am attempting in SSIS,

(__$operation == 4) && (((DT_I8)__$update_mask & @[User::SCDColumnNumber]) > 0)

The corresponding TSQL code will be

SELECT 
CASE WHEN (CAST(__$update_mask as int) & 16)>0 THEN 1 ELSE 0 END ScdType2,
CAST(__$update_mask as int) Change,
* FROM 
cdc.fn_cdc_get_net_changes_dbo_Transactions
(sys.fn_cdc_get_min_lsn('dbo_Transactions')
,sys.fn_cdc_get_max_lsn(),'all with mask')

which is working fine. But the SSIS CAST is not. Hope this gives enough information about my query.

A: 

What is in the varbinary? Is it of variable length? How do you know there are integers in that data?

John Saunders
It is holding an integer value only. Yes the length is variable.And please post this kind of queries as comments instead of answers.
Faiz
I posted it as an answer because it was meant to be edited into an answer once I heard back from you.
John Saunders
You also haven't answered the last part of the question: how do you know that only integers are in the data? In particular, do you have the code that put the integers into the data? If so, you should post that code. Otherwise, we would only be making guesses about things like byte order.
John Saunders
I have added more details on the query in the question. Please check.
Faiz
A: 

The __$update_mask column is of type varbinary, length 128 bytes. There is no way it can be casted (without loss of information) to INT or BIGINT as the cast destination sizes are 4 and 8 bytes respectively. Though I wanted to consider only first 8 bytes of the 128 bytes. But again, I couldn't find any supported data type or casting in SSIS that can do the job. Though this can be done in DB engine and brought to SSIS later.

Faiz

related questions