exporting row with newline character to a text file

  • I have a text data type column in SQL Server. I want to export that data to text file using the bcp utility. Each row in the column has to be split into several lines while exporting to text file. For example the data 'abcd \n efgh' has to be exported into text file with abcd on one line and efgh on the next line.

    Please suggest what character I shoul include in the data so as to cause the data to split while exporting to text file.

    Thanks

    Regards

    Satish

     

  • CHAR(13) "Carriage Return" and possibly follow with CHAR(10) "Line Feed"

    --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)

  • Thanks Jeff

    I had actually tried using char(13) and char(10) nut it didnt help

    Regards

  • Jeff's answer should work, eg

    bcp "select 'abcd'+CHAR(13)+CHAR(10)+'efgh'" queryout test.txt -S servername -T -c

    will produce a text file with

    abcd

    efgh

     

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Thanks Jeff and David

    It works.

    Seems I was trying char(10) and char(13) in the wrong order.

    It works only in a specific order

    First char(13) and then char(10)

    Thanks again

    Sunny

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

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