How to migrate empty strings from DB2 to SQL Server?

rsl1atfo  于 2023-05-21  发布在  DB2
关注(0)|答案(1)|浏览(170)

I'm going to export DB2 data to CSV file and want to use it with bcp command to import to SQL Server

I have a problem with empty string migration.In bcp, an empty character is a control code of 0x00, so when exporting on the DB2 side I'm trying to output a file with empty characters as 0x00:

export to /tmp/output5.csv of DEL MODIFIED BY NOCHARDEL
select 
CASE WHEN COL2 = '' THEN BINARY('',1) ELSE COL2 END AS COL2,
CASE WHEN COL3 = '' THEN BINARY('',1) ELSE COL3 END AS COL3
from TBL1
;

I got SQL Error:

SQL0581N The data types of the result-expressions of a CASE expression or DECODE function are not compatible. SQLSTATE=42804

How to output a control code to a file when the data is an empty string?

smdnsysy

smdnsysy1#

Using x'00' instead of BINARY('',1) seems to work fine.

export to /tmp/output.csv of DEL MODIFIED BY NOCHARDEL
select 
CASE WHEN COL2 = '' THEN x'00' ELSE COL2 END AS COL2,
CASE WHEN COL3 = '' THEN x'00' ELSE COL3 END AS COL3
from TBL1

相关问题