문제

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