简体   繁体   English

如何使用批处理将数据从 sql 导出到 excel - 在 sql 中的每一列中导出一列?

[英]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.

相关问题 使用导入导出向导将数据从 Excel 导入 Sql Server 时,如何更改列的默认 varchar 255? - How does one change the default varchar 255 of a column when importing data from Excel to Sql Server using Import Export Wizard? 在 C# 中将 CSV 导出到 SQL - 如何将导出偏移一列 - Exporting CSV to SQL in C# - how to offset the export by one column 使用列标题从 SQL Server 导出到 Excel? - Exporting from SQL Server to Excel with column headers? 使用多个值的Excel列从Excel导出到SQL Server - Export from Excel to SQL Server with Excel Column of Multiple Values 如何通过使用SSIS包每小时从Excel到SQL Server表中仅插入一行 - How to insert only one row per hour from Excel into a SQL Server table by using SSIS package 将网格视图 (SQL Server Management Studio) 中的 SSMS 中的数据粘贴到 Excel 时,所有列数据都在一个列中 - While pasting data from SSMS in Grid view (SQL Server Management Studio) to Excel, all the column data is in one single column 如何将SQL数据导出到excel - How to export SQL data in to excel 使用openrowset从SQL将数据导出到Excel时出现错误 - while exporting data to excel from sql using openrowset getting error 无法从SQL Server导出数据到Excel - Exporting data to excel from sql server is not working 将数据从 Excel 导出到 SQL 服务器 - VBA - Exporting Data from Excel to SQL Server - VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM