SQLCmd Example to Output in CSV Format
August 5th, 2009 by Andrew Chen
SQLCmd is a very handy tool used to execute SQL script automatically and output results to a file. Here is an example:
sqlcmd -S “ServerName” -U “UID” -P “PWD” -d “DBName” -i “c:\input.txt” -o “c:\output.txt” -s “,” -h -1
The parameter names in command line are case sensitive. So -D is different from -d. As shown in the example most of the parameters are self-explanatory. You can use SQLCmd /? to display all applicable parameters. Parameter -h -1 instructs the utility not to output result set header. Parameter -s “,” instructs the utility to use comma as column separator. The default is to a space.


No comments yet.