sqlcmd output csv double quotes round fields

  • Can anyone tell me how I could get all my fields to be not only comma separated but quote (") delimited.

    i.e.

    current output

    FRED,SMITH,3 THE STREET,ANYWHERE

    preferred output

    "FRED","SMITH","3 THE STREET","ANYWHERE"

    Only sqlcmd usage allowed.

  • You could try and use the QUOTENAME function or add double quotes around the fields

    sqlcmd -S localhost -E -Q "select '""' + [name] + '""', QUOTENAME ([number], '""'), QUOTENAME ([type], '""') from spt_values" -o "Test.csv" -h-1 -s"," –W

    I have not found a way with the sqlcmd options yet.

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

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