Reputation: 14108
Goal:
I want to add some name of the column's header from stored procedure to the CSV file
bcp "EXEC [databasname].[storedprocedure]" queryout C:\test\bcp_outputTable.csv -c -T -SPC01 -r\n
Problem:
I cannot find a solution to it.
Info:
I'm using the code above in CMD.
Upvotes: 0
Views: 505
Reputation: 14108
@ECHO off
SET "location=c:\test\" SET filename=%date:~0,10%
ECHO This bat creates a csv file to the to the folder %location% ECHO If you are ready, press the button space
PAUSE
BCP "[databasname].[storedprocedure]" queryout %location%%filename%.txt -c -T -t; -SPC01 -r\n
:: Adding header in the csv file ECHO f;f;f> %location%%filename%.csv
TYPE %location%%filename%.txt >> %location%%filename%.csv
DEL /s %location%%filename%.txt
PAUSE
Upvotes: 0
Reputation: 56238
rename "C:\test\bcp_outputTable.csv" "C:\test\bcp_outputTable.txt"
echo HeadRow1,HeadRow2,HeadRow3,... >"C:\test\bcp_outputTable.csv"
type "C:\test\bcp_outputTable.txt>>"C:\test\bcp_outputTable.csv"
del "C:\test\bcp_outputTable.txt"
Upvotes: 1