简体   繁体   English

如何在Microsoft SQL Server Management Studio中将查询结果导出到csv?

[英]How to export query results to csv in Microsoft SQL Server Management Studio?

Trying to export custom query to csv file I wrote the following command: 尝试将自定义查询导出到csv文件中,我编写了以下命令:

sqlcmd [-S myserver -d mydb -E -Q "SELECT column1 ,column_date, DATENAME(WEEKDAY, column_date) AS day_of_week ,distinc_events_count ,total_events_count ,event_duration FROM dbo.event_daily_stats ORDER BY column1" -o "D:\MyData.csv" -h-1 -s"," -w 700]

but it returned the following error message: 但它返回以下错误消息:

The identifier that starts with '-S myserver -d mydb -E -Q "SELECT column1 ,column_date, DATENAME(WEEKDAY, column_date) AS day_of_week ,distinc_events_count ,' is too long. Maximum length is 128.

Does anyone know how this issue could be solved? 有谁知道如何解决这个问题?

Thank you! 谢谢!

我毫无问题地执行了没有“ [”和“]”的命令,您是否尝试过这种方式?

sqlcmd -S myserver -d mydb -E -Q "SELECT column1 ,column_date, DATENAME(WEEKDAY, column_date) AS day_of_week ,distinc_events_count ,total_events_count ,event_duration FROM dbo.event_daily_stats ORDER BY column1" -o "D:\MyData.csv" -h-1 -s"," -w 700

我认为问题在于,当您尝试在命令提示符下运行它时,您正在尝试在SSMS中运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft SQL Server Management Studio导出XML数据类型列 - Export XML data type column with Microsoft SQL Server Management Studio 如何使用SQL Server将多个查询结果导出到csv? - How to export multiple query results to csv using SQL Server? 如何在 SQL Management Studio 中将 SQL 查询的结果导出为 .csv 文件(使用代码) - How to export the result of an SQL query as a .csv file in SQL Management Studio (using code) SQL Server Management Studio 2012 - 将数据库的所有表导出为 csv - SQL Server Management Studio 2012 - Export all tables of database as csv 通过Management Studio从SQL Server 2012导出到.CSV - Export from SQL Server 2012 to .CSV through Management Studio 使用SQL Server Management Studio自动导出为CSV - Automated Export to CSV Using SQL Server Management Studio 如何在 SQL Server Management Studio 中以“真实”CSV 格式导出 output? - How to get export output in "real" CSV format in SQL Server Management Studio? Microsoft SQL Server Management Studio - 查询结果为文本 - Microsoft SQL Server Management Studio - query result as text Microsoft SQL Server Management Studio错误地重写我的查询 - Microsoft SQL Server Management Studio Rewrites my query incorrectly 如何使用Microsoft SQL Server Management Studio将查询结果转储到文件中 - How can I dump the result of a query into a file using Microsoft SQL Server Management Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM