BCP command to import data from txt file (Pipe as Field terminator)into SQL Table.

  • Hi all

    I am facing hard time in configuring the BCP command to to import data from txt file (Pipe as Field terminator)into SQL Table.

    As the TAB is the default field terminator for BCP. And My source file is | (Pipe delimited file)

    I tried this

    BCP Work.dbo.Customer IN "\\MyMechine\Shared\Cust.txt" -T -S "SQLSERVER" -t|

    Am I missing some thing here.

    Please help me.

  • anand_vanam (8/6/2011)


    Hi all

    I am facing hard time in configuring the BCP command to to import data from txt file (Pipe as Field terminator)into SQL Table.

    As the TAB is the default field terminator for BCP. And My source file is | (Pipe delimited file)

    I tried this

    BCP Work.dbo.Customer IN "\\MyMechine\Shared\Cust.txt" -T -S "SQLSERVER" -t|

    Am I missing some thing here.

    Please help me.

    Are you getting an error or what? You haven't told us what the problem actually is. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • SQLState = S1000, NativeError = 0

    Error = [Microsoft][SQL Server Native Client 10.0]Unexpected EOF encountered in

    BCP data-file

    0 rows copied.

    I got this Error.

    I even added the "format file".

    I have 3 columns in the Table. No Identtity Column. and No PK's

    CREATE TABLE dbo.Cust

    (Sno INT,

    Name Varchar(20),

    Location Varchar(30)

    )

    And the .txt file has 3 columns... with Pipe delimited.

    Ex:

    1|Cust1|Newyook

    2|John|Washington

    100|Alan|Seattle

  • my bcp OUt exampel shows the delimiter between dbl quotes, and not the sole char after the -t.

    try that...

    also check your row terminator; if it's not CrLf, you might need to change /add the -r command for the row terminator:

    -r"\r"

    EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT * FROM ##PIPE_REPORT " queryout C:\Data\Objects.txt -t"|" -c -T '

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks that helped alot.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply