Вопрос

I'm trying to generate a CSV file with BCP. My problem is that I have some NVARCHAR columns so I must use the parameter -w for the bcp utility. So, the CSV file generated is opening in a single column in EXCEL. If I create a new text file copy the content of the CSV generated and paste in the new file and then change its type to CSV it works and open the content spread in different columns. Has someone seen it before?

SET @File = 'MyQuery.csv'
set @SQL = 'bcp "SELECT FirstName, LastName, DwellingName FROM Table" queryout "' +  + '" -w -t 
"," -T -S '+ convert(varchar,@@ServerName)
exec master..xp_cmdshell @SQL
Это было полезно?

Решение

I've found a solution for my problem:

I've used the -CACP to generate the CSV file ANSI Encoded and it works!!!

Now my command looks like:

SET @File = 'MyQuery.csv'
set @SQL = 'bcp "SELECT FirstName, LastName, DwellingName FROM Table" queryout "' +  + '" -c -CACP -t "," -T -S '+ convert(varchar,@@ServerName)
exec master..xp_cmdshell @SQL
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top