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.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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 5 years, 5 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