Export to CSV

  • Jenny77

    Valued Member

    Points: 62

    Hi,

     

    i am trying to export a table into csv, and it should be comma delimited with doublequotes around each value like this:

    "value1","value2","value3"

    this works fine, but one of the columns includes doublequotes as part of the value, so when its exported to csv, it breaks it into multiple columns. Anyone knows the best way to handle this so that its not splitting it up into multiple columns?

     

     

     

  • Jeff Moden

    SSC Guru

    Points: 994555

    Jenny77 wrote:

    Hi,

    i am trying to export a table into csv, and it should be comma delimited with doublequotes around each value like this:

    "value1","value2","value3"

    this works fine, but one of the columns includes doublequotes as part of the value, so when its exported to csv, it breaks it into multiple columns. Anyone knows the best way to handle this so that its not splitting it up into multiple columns?

    Yes.  It's part of the "standard" for proper "CSV" creation (Google for it).  You have to double up on embedded quotes to "escape" them properly.

    --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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

  • scdecade

    Old Hand

    Points: 377

    What have you tried?  As I recall SSMS export will not properly escape the text.  I'm pretty sure tho SSIS csv export does.

Viewing 3 posts - 1 through 3 (of 3 total)

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