Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Export with BCP - Problem with varbinary and trailing zeros


Export with BCP - Problem with varbinary and trailing zeros

Author
Message
Alex-489474
Alex-489474
SSC Veteran
SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)

Group: General Forum Members
Points: 292 Visits: 142
Hello Community!

I am having a problem with the export of data via bcp from an Sql Server 2008 instance. The table that I am exporting has the following definition:

IDEvent (PK, uniqueidentifier)
MessageType (tinyint)
MessageVersion (tinyint)
LogTime (datetime)
RawData (varbinary(8000))

The table is used to store production information. In the column "RawData", the binary information of the complete production message is stored. The data could look like the following: "0X08200000018E15430000". In the source database, the RawData is stored in the correct format.

If I am exporting and then importing the data into a different instance, the information from "RawData" is imported as "0X08200000018E1543". That leads to problems in the further program flow as the missing Bytes are causing exceptions.

I am calling bcp with the following command for the export: "Bcp exportTabel out D:\tmp\exportTable.dat -n -S ..."
For the Import: "Bcp exportTable in D:\tmp\exportTable.dat -n -S ..."
Which options for bcp do I have to add so that my binary data is imported in the correct format?

Checking the ANSI Padding with the command "SELECT SESSIONPROPERTY('ANSI_PADDING') " gave me the result "1". So the padding should be active on the export and import instance.

Which options do I have so that the trailing zeros are not lost during the export/import process?

Thank you for your help.
Alex
higgim
higgim
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1035 Visits: 2614
Probably not the most elegant of solutions however when we used BCP to export data with leading and trailing zeros we converted depending on which way we were going.

DECLARE @something AS VARBINARY(MAX)

DECLARE @somethingelse AS NVARCHAR(MAX) = '0X08200000018E15430000'

SELECT @something = CONVERT(VARBINARY(MAX), @somethingelse)

SELECT CONVERT(NVARCHAR(MAX), @something)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search