Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 bcp out empty string into csv files

Author  Topic 

rkjayaraj
Starting Member

2 Posts

Posted - 2008-06-19 : 10:05:17
I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL character. Is there any way I can bcp out empty string as empty string itself instead of NUL to the file?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-19 : 10:11:19
I have encountered this before.
An empty string is BCP'ed out as NULL, and a string with one space ' ' is BCP'ed out as an empty string.

I think we will have to look at your code to decide what is wrong.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-19 : 10:21:20
quote:
Originally posted by rkjayaraj

I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL character. Is there any way I can bcp out empty string as empty string itself instead of NUL to the file?


Probably you could try specifying a format file for bcp and try

http://doc.ddart.net/mssql/sql70/impt_bcp_16.htm

http://www.nigelrivett.net/SQLTsql/BCP_quoted_CSV_Format_file.html
Go to Top of Page

rkjayaraj
Starting Member

2 Posts

Posted - 2008-06-20 : 03:01:05
Thanks for your help.

The bcp command I used to export table into csv file is

bcp "SELECT skillID,profileID,skillName,active,dateInactive from db_cra..Skill" queryout C:\Skill.csv -w -S 10.76.253.70\CRSSQL -t"," -T

In the table skillName column can have empty string value. Corresponding to the empty string csv file contain 'NUL' stored in it. I do not want 'NUL'. I need empty string in the resulting file.
Is there any way it can be done?
Go to Top of Page
   

- Advertisement -