开发者

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

开发者 https://www.devze.com 2023-01-20 03:20 出处:网络
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

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 identifie开发者_开发百科r 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!


I executed the command without "[" and "]" with no problem, have you tried in this way?

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


I think the problem is that you're trying to run this inside of SSMS when it should be run at a command prompt instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消