sqlcmd

Conditional logic in PostDeployment.sql script using SQLCMD

和自甴很熟 提交于 2019-11-26 12:08:30
问题 I am using a SQL 2008 database project (in visual studio) to manage the schema and initial test data for my project. The atabase project uses a post deployment which includes a number of other scripts using SQLCMD\'s \":r \" syntax. I would like to be able to conditionally include certain files based on a SQLCMD variable. This will allow me to run the project several times with our nightly build to setup various version of the database with different configurations of the data (for a multi

How to export data as CSV format from SQL Server using sqlcmd?

心已入冬 提交于 2019-11-25 23:34:05
问题 I can quite easily dump data into a text file such as: sqlcmd -S myServer -d myDB -E -Q \"select col1, col2, col3 from SomeTable\" -o \"MyData.txt\" However, I have looked at the help files for SQLCMD but have not seen an option specifically for CSV. Is there a way to dump data from a table into a CSV text file using SQLCMD ? 回答1: You can run something like this: sqlcmd -S MyServer -d myDB -E -Q "select col1, col2, col3 from SomeTable" -o "MyData.csv" -h-1 -s"," -w 700 -h-1 removes column