bcp command is replacing empty strings with nulls

bcp sqlbulkcopy sql-server

Question

The following bcp command is auto converting empty strings to nulls:

BCP "stored_proc_name" queryout C:\Outdir\data.csv -c -t , -T -Sserverx -Uusery -Ppassz -dproddb

I need the empty strings to be retained and not be replaced by NULLs.

What's the best way to do this? Can the bcp auto conversion be turned off?

1
0
6/27/2015 11:10:08 AM

Popular Answer

The best way is to leave null value not empty string on database. Then BCP will export empty string into file (.csv, .txt or so).

Please refer to BCP MSDN:

  • out copies from the database table or view to a file. If you specify an existing file, the file is overwritten. When extracting data, note that the bcp utility represents an empty string as a null and a null string as an empty string.
1
7/11/2017 10:07:51 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow