Skip to content

Instantly share code, notes, and snippets.

@martin0258
Created July 30, 2013 01:11
Show Gist options
  • Save martin0258/6109359 to your computer and use it in GitHub Desktop.
Save martin0258/6109359 to your computer and use it in GitHub Desktop.
Get a CSV file from database query result.
:: -U, user name
:: -P, password
:: -h-1 [removes column name headers from the result]
:: -s"," [sets the column seperator to ,]
:: -w 1000 [sets the row width to 1000 chars (need to be as wide as the longest row or it will wrap to the next line)]
:: -W [remove trailing spaces from each individual field]
:: set nocount on; set ansi_warnings off; [in SQL file to remove additional messages] >
:: extract source file
sqlcmd -S %SERVER% -d %DB_NAME% -U %ARG1% -P %ARG2% -h-1 -s"," -W -w 1000 -i "%SQL_FILE%" -o "%RAW_FILE%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment