Learn how to a build a cloud-first strategyRegister Now


Using | as field terminator in BCP queryout

Posted on 2008-11-13
Medium Priority
Last Modified: 2012-06-27
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?

Question by:thewayne73
  • 2
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22950943
Can you post the command-line you're using?

-t| should work according to BOL.

Author Comment

ID: 22951258
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


'-c' is not recognized as an internal or external command,
operable program or batch file.

Accepted Solution

thewayne73 earned 0 total points
ID: 22952388
Figured it out.


Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question