thewayne73
asked on
Using | as field terminator in BCP queryout
Hello Experts,
I am using BCP to export data from a SQL statement to a test file using queryout. I want to use | as my field terminator, but only seem to be able to get it to output , as a field terminator using -t,
Is it possible to use | as a field terminator?
thanks
I am using BCP to export data from a SQL statement to a test file using queryout. I want to use | as my field terminator, but only seem to be able to get it to output , as a field terminator using -t,
Is it possible to use | as a field terminator?
thanks
ASKER
Thanks Daniel,
Below is the script...and the error I am receiving. If I remove the | or replace it with ,....it runs fine.
declare @move_dt datetime
, @move_yyyymmdd varchar(8)
, @move_letter_file_location varchar(2000)
, @bcp_move_cmd varchar(2000)
set @move_dt = convert(datetime,'7/1/2008 ',101)
set @move_yyyymmdd = right(replicate('0',4) + cast(datepart(yyyy, @move_dt) as varchar(4)),4) + right(replicate('0',2) + cast(datepart(mm, @move_dt) as varchar(2)),2) + right(replicate('0',2) + cast(datepart(dd, @move_dt) as varchar(2)),2)
set @move_letter_file_location = '\\server\move_' + @move_yyyymmdd + '.txt'
set @bcp_move_cmd = 'bcp "select * from database..address_view where (right(replicate(''0'',4) + cast(move_yyyy as varchar(4)),4)) + (right(replicate(0,2) + cast(move_mm as varchar(2)),2)) + (right(replicate(0,2) + cast(move_dd as varchar(2)),2)) = ''' + @move_yyyymmdd + ''' order by 3" queryout "'
set @bcp_move_cmd = @bcp_move_cmd + @move_letter_file_location + '" -t| -c -SDEV_SQL -T'
EXEC master..xp_cmdshell @bcp_move_cmd
ERROR
'-c' is not recognized as an internal or external command,
operable program or batch file.
NULL
Below is the script...and the error I am receiving. If I remove the | or replace it with ,....it runs fine.
declare @move_dt datetime
, @move_yyyymmdd varchar(8)
, @move_letter_file_location
, @bcp_move_cmd varchar(2000)
set @move_dt = convert(datetime,'7/1/2008
set @move_yyyymmdd = right(replicate('0',4) + cast(datepart(yyyy, @move_dt) as varchar(4)),4) + right(replicate('0',2) + cast(datepart(mm, @move_dt) as varchar(2)),2) + right(replicate('0',2) + cast(datepart(dd, @move_dt) as varchar(2)),2)
set @move_letter_file_location
set @bcp_move_cmd = 'bcp "select * from database..address_view where (right(replicate(''0'',4) + cast(move_yyyy as varchar(4)),4)) + (right(replicate(0,2) + cast(move_mm as varchar(2)),2)) + (right(replicate(0,2) + cast(move_dd as varchar(2)),2)) = ''' + @move_yyyymmdd + ''' order by 3" queryout "'
set @bcp_move_cmd = @bcp_move_cmd + @move_letter_file_location
EXEC master..xp_cmdshell @bcp_move_cmd
ERROR
'-c' is not recognized as an internal or external command,
operable program or batch file.
NULL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-t| should work according to BOL.