January 25, 2021 at 2:02 am
I've been playing around wiht bcp out the data into csv file but been getting this error. I've a setup a table where I read the table name, servername, database name, filepath and build a dynamic query through stored procedure. But I've been getting below error and can't seem to figure out. If anybody has any idea, really appreciate it.
BCP Select * From [BI-EDW].EAP.EAP.vw_file queryout \\bi-qservername\eap\Extracts\raw-can-mwia--file_ss-interval_20210123_20210124_dumpedon_20210124.csv -S BI-EDW -d EAP-T -r"\r" -t "|" -c -C 65001 -e \\bi-qservername\eap\Extracts\file_errors.txt
Msg 102, Level 15, State 1, Line 12
Incorrect syntax near '\'.
code snippet:
if @PullType = 'I'
begin
SET @QUERY = ' Select * From ' + '[' + @server + ']' + '.' + @Database + '.' + @Schema + '.' + 'vw_'+ @TABLE
SET @FileName = @FilePrefix + '-' + @Table + '_ss-interval_' + convert(varchar, @StartDate, 112) + '_' + convert(varchar, getdate(), 112) + '_dumpedon_' + convert(varchar, getdate(), 112) + '.csv'
SET @QUERY = @QUERY + ' queryout ' + @FilePath + @FileName + ' -S' + ' ' + @server + ' -d ' + @Database + '-T ' + ' -r' + '"\r"' + ' -t' + ' "|"' + ' -c ' + ' -C ' + ' 65001 ' + ' -e ' + @FilePath + @Table +'_errors.txt'
--
end
else
begin
SET @QUERY = ' Select * From ' + '[' + @server + ']' + '.' + @Database + '.' + @Schema + '.' + @TABLE
end
SET @CMD = 'BCP ' + @Query
print @CMD
exec sp_executeSQL @CMD
January 25, 2021 at 9:12 am
The path to the UNC place needs to be double quoted
BCP Select * From [BI-EDW].EAP.EAP.vw_file queryout "\\bi-qservername\eap\Extracts\raw-can-mwia--file_ss-interval_20210123_20210124_dumpedon_20210124.csv" -S BI-EDW -d EAP-T -r"\r" -t "|" -c -C 65001 -e "\\bi-qservername\eap\Extracts\file_errors.txt"
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply