0

I'm using SSIS to import several fields from a DB2 database on an IBM I-series. The fields are 1 character (1 byte) and each of the 8 bits represents a different flag, so 00000001 might mean the account is new, 10000000 might mean that a statement was dropped today, and 10000001 would mean that both flags are 'On'. The fields are already imported into SQL char(1) from a flat file generated from the I-Series. I do have access to the flat files if necessary.

Casting to varbinary returns 0x20 when none of the bits are on when I would expect zero.

I tried a script task:

        flags = Row.lnflg4.ToCharArray()[0];
        bits = Convert.ToString(flags, 2).PadLeft(8, '0');

How can I get the binary value so I can split that into 8 separate bit fields in SQL Server? Or get the binary, then convert that to decimal so I could use 1 as the 'New Account value' and 128 as the statement value with 129 as both? Or something else?

craday
  • 21
  • 3
  • You're after a bitwise and to mask the info off https://learn.microsoft.com/en-us/sql/t-sql/language-elements/bitwise-and-transact-sql – Jay Wheeler Aug 25 '17 at 21:19
  • That results in this error : Conversion failed when converting the varchar value '' to data type int. The funky looking character is a hex 0x10, which is an ASCII data link escape. The more I look at it the more I think it can't be done from the sql side. The hex 0x00 are coming over as 0x20 (a space) and the problem with that is I can't tell if it is a legitimate flag like this : 00100000 – craday Aug 28 '17 at 15:49

0 Answers0