简体   繁体   中英

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:

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中运行它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM