Ask SQLTeam Question
Posted - 08/12/2002 : 08:26:35
| Shweta writes "Hi,
I have an SP that creates a csv file from sqlserver 2000.
It works well but if a field value has comma then also it makes it as a column.
Is there any way so that I can get CSV file with columns enclosed in double quotes.
Here is the SP.
-- This Sql will Transfer SQL Server Table to .CSV
DECLARE @PATH VARCHAR(30)
DECLARE @DB VARCHAR(30)
DECLARE @TBl VARCHAR(30)
DECLARE @CMD VARCHAR(500)
DECLARE @QRY VARCHAR(500)
SET @PATH = 'C:\dts\'
set @TBl = 'authors'
set @DB = 'HRISTEST'
-- in transfer excel to Sql, Out transfers sql to Excel
SELECT @CMD = 'bcp ' + @DB + '..' + @TBl + ' out ' + @PATH + --@DB
@TBl +'.CSV' + ' -c -t \t -r \n '--/F 2'
EXECUTE master..xp_cmdshell @cmd"