Tuesday, 24 July 2018

BCP SQL Export By Casting all columns as text


BCP Export By Casting all columns as text
 
You have to concatenate the columns with quotes, except the date columns as follows.

You also have to union all the column name headers with the values.

bcp "SELECT 'coldate' as coldate ,'col2' as col2 ,'col3' as col3 union all select convert(varchar(max),[coldate],120) ,char(34)+[col2]+char(34) ,char(34)+[col3]+char(34) FROM [database].[schema].[Table_Name];" queryout "filePath\csvFile.CSV" -t "," -c  -q  -C 65001 -S"ServerName" -U"UserName" -P"Password"

No comments:

Post a Comment