sqlcmd to export to txt file - not working

  • First time exporting contents of tables to a txt file.  Need to keep NULLs instead of empty blanks that are generated by export wizard.  So, want to use sqlcmd.

    Tried:

    sqlcmd -s servername -d dbname -E -Q "SELECT * FROM [Schema].[dbo].[Inventory]" -s "," -o "\\address.org\vdifolders$\polkadot\Documents\US570333\Inventory.txt"

    get error:

    Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 's'.

    Tried

    sqlcmd -i servername -d dbname -E -Q "SELECT * FROM [Schema].[dbo].[Inventory]" -s "," -o "\\address.org\vdifolders$\polkadot\Documents\US570333\Inventory.txt"

    get error:

    Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'i'.

    basically whatever switch I use after sqlcmd, gives error. It's as though SSMS doesn't recognize sqlcmd utility .  Tried turning it on within SSMS by toggling SQLCMD Mode from Query drop down.

    Does the syntax look right?  Why the failure?  Ideas? Suggestions?

    --Quote me

  • Specifying servername requires uppercase S "-S", specifying separator is lowercase s "-s". -i is for a sql file, usually used instead of -Q or -q.

  • You are using command line sqlcmd, so SSMS is not relevant here.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Relief to learn I am to use command line!  thank you.

    got it to work with

    sqlcmd -S servername -d dbname -E -Q "SELECT * FROM [Schema].[dbo].[Inventory]" -s "," -o "\\address.org\vdifolders$\polkadot\Documents\US570333\Inventory.txt"

    • This reply was modified 4 years, 11 months ago by  polkadot.

    --Quote me

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

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