[英]How to export data from sql to excel using batch - exporting one column in sql per one column in excel?
I am exporting sql view using.bat script:我正在使用.bat 脚本导出 sql 视图:
sqlcmd -U HPH_COM -P HPH_COM -S vTF-DB\LEVEL2 -d HPH_COM -Q " SELECT TOP (1000) * FROM HPH_COM.dbo.REP_TEMP_STOCKS_LASTDAY " -o "C:\sajtovi\TF1_PyroMeasuresLastDay.csv"
And its working.及其工作。 However, exported
csv
file is not organized as when you export using SSMS: using batch one column in sql is not copied to one column in excel, but more columns from sql to one column in excel. However, exported
csv
file is not organized as when you export using SSMS: using batch one column in sql is not copied to one column in excel, but more columns from sql to one column in excel. so i cannot play with exported data.所以我不能玩导出的数据。 Any idea how to write script which will give same results as exported with
ssms
?知道如何编写与使用
ssms
导出的结果相同的脚本吗?
Thanks谢谢
you can use these options.您可以使用这些选项。
-h rows_per_header
-s col_separator
-W (remove trailing spaces)
and also specify set nocount on
to prevent the completion message from appearing.并指定
set nocount on
以防止出现完成消息。
It looks like this.它看起来像这样。
sqlcmd -U HPH_COM -P HPH_COM -S vTF-DB\LEVEL2 -d HPH_COM -Q "set nocount on; SELECT TOP (1000) * FROM HPH_COM.dbo.REP_TEMP_STOCKS_LASTDAY " -o "C:\sajtovi\TF1_PyroMeasuresLastDay.csv" -W -h -1 -s,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.