tags:

views:

38

answers:

2

Hi,

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!

+2  A: 

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
il_guru
It returns an error: Incorrect syntax near 'S'.
niko
I pasted the command changing only the query, myserver and mydb values and i did not receive any error. Maybe you accidentally deleted the "-" before "S". Can you paste the command you used?
il_guru
+1  A: 

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.

Joe Stefanelli