Friday, February 17, 2012

Export table containing BIT data

I'm trying to export a table that contains a bit field into a text file to be used for a bulk insert into another database.

when i export the data from SQL enterprise manager, the bit field is exported as the text TRUE or FALSE ?!!!

this data then cant be bulk inserted as its not a BIT anymore.

how can bit fields be properly exported as 1 or 0 ?Are you doing this in a DTS Package? Use CAST or CONVERT on the BIT field and change the output to an INTEGER or CHAR(1). They are basically the same thing but in this scenario either or is fine; since BIT transformation are not explicit and generally require no intervention to get the value of 1 or 0, however if I'm not mistaken, using a Text ODBC driver causes BITs to be converted to TRUE/FALSE. That's why I asked if you are using DTS, it's ODBC driven. If you are using DTS, you will need to write a query in the Source tab using one of the functions below.

Using CAST

CAST(bYourBit AS INTEGER) AS bYourBit

Using CONVERT
CONVERT(CHAR(1),bYourBit) AS bYourBit

No comments:

Post a Comment