Click here to Skip to main content
15,881,877 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am using bcp command in sql server to export data generated from a query to .csv file with the help of following command

SQL
xp_cmdshell bcp "select * from table1" QUERYOUT /c /t, -T -S 


It is working fine and exporting data as expected but now we have a column which contain multilingual data and during exporting with above command data in csv file shows as "????????".

After doing some googling I found some other switch like -w instead of /c to be used for unicode character but this option is creating unicode file and does not open in excel properly(columns are not separated by comma(,)). I also noticed that if I remove /t, then its separating the column and looks fine but here column is separated by tabs not comma which I don't need.

Can anybody help me if I am missing anything?
Posted
Updated 25-Sep-13 4:11am
v2
Comments
RedDk 25-Sep-13 14:06pm    
Possibly the -C option needs to be set. Specific codepage can be input, if its not ACP, OEM, or RAW. Isn't there a way to say it in TSQL also, using same keywords, somewhere in the " " string?

See http://technet.microsoft.com/en-us/library/ms162802.aspx

1 solution

Please, read the comment of RedDK and follow the link provided by Him:
RedDK wrote:
Possibly the -C option needs to be set. Specific codepage can be input, if its not ACP, OEM, or RAW. Isn't there a way to say it in TSQL also, using same keywords, somewhere in the " " string?
See http://technet.microsoft.com/en-us/library/ms162802.aspx[^]

and have a look here[^].

Instead:
SQL
xp_cmdshell bcp "select * from table1" QUERYOUT /c /t, -T -S 

try to use:
SQL
xp_cmdshell bcp "select * from table1" QUERYOUT -w -t, -T -S 

Do not forget to define codepage!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900