Using | as field terminator in BCP queryout

Posted on 2008-11-13
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
    LVL 32

    Expert Comment

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

    -t| should work according to BOL.

    Author Comment

    Thanks Daniel,

    Below is the script...and the error I am receiving.  If I remove the | or replace it with , 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

    Figured it out.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
    In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now