Frage

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
War es hilfreich?

Lösung

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top