Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2010
    Posts
    3

    Unanswered: Quotes around the data exported in bcp command

    Hello,

    I am exporting out of a SQL database into a CSV file. I forgot to mention in a earlier post that this export is done with a bcp command. I would like to put double quotes around the data. In the bcp command, I have tried -t"," but this does not work. I cannot put the quotes right into the query because that does not seem to work. I was wondering what I can do. Thank you for all of your help!

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    You may need to add an escape to let the OS know that the quotes should be passed to the bcp command. Even if that works, it's just the separator, so the first and last columns won't have the quotes.

    So additionally, you could specify a query adding the quotes to the first and last columns, for example:
    Code:
    bcp "select '\"'+convert(varchar,myint), <the other columns>, myvar+'\"' from ...." queryout thefile.csv -c -T -S <server> -t\",\"
    I don't know how that works for you, query and maintenance wise.

  3. #3
    Join Date
    Nov 2010
    Posts
    3
    Thank you, I will try it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •