locked
SQLCMD adding a text qualifier RRS feed

  • Question

  • How in the world do I add a text qualifier to an output result set in a csv file?

    My code is as follows:

    sqlcmd -S database_servername -i e:\sqldata\mysqlscript.sql -o\\shared_networkserver\directory\folder\subfolder\myoutput.CSV -s ","  -W




    Now that works fine except I want my result set to look like this: "fieldresult1", "fieldresult2", "fieldresult3"

    Basically have them in double qoutes and separated by a comma.

    Thanks in advance
    Network Analyst
    Tuesday, February 2, 2010 2:10 AM

Answers

  • You can add quotes in your query like this:

    select '"' + isnull(column1,'') + '"', '"' + isnull(cast(column2 as varchar),'') + '"'
    from t1

    column2 is numeric datatype

    With kind regards
    Krystian Zieja
    http://www.projectenvision.com
    • Marked as answer by Frank Ivey Tuesday, February 2, 2010 4:29 AM
    Tuesday, February 2, 2010 2:33 AM

All replies

  • You can add quotes in your query like this:

    select '"' + isnull(column1,'') + '"', '"' + isnull(cast(column2 as varchar),'') + '"'
    from t1

    column2 is numeric datatype

    With kind regards
    Krystian Zieja
    http://www.projectenvision.com
    • Marked as answer by Frank Ivey Tuesday, February 2, 2010 4:29 AM
    Tuesday, February 2, 2010 2:33 AM
  • Kyrstian, thanks so much

    That really helped me and that was the answer i was looking for
    Network Analyst
    Tuesday, February 2, 2010 4:29 AM