Raven Raven - 2 months ago 10
SQL Question

Sqlcmd query in mutliple database "Unexpected argument"

I have an SQL query which i need to run on multiple instanses through one request.

Use Extracts
DECLARE @RunDate DATETIME;
DECLARE @WeeklyRunDate DATETIME;
SET @RunDate = '2016/08/31'
SET @WeeklyRunDate = (select DATEADD(dd, -(DATEPART(dw, @RunDate)-1), @RunDate))
Update Extracts..Processlastruns
Set Proclastrunsystemdate =@WeeklyRunDate , proclastwritesystemdate =@WeeklyRunDate
Where Procrunid in(select Procrunid From Extracts..Processruns Where Procrunenabled ='1' and Procrunfreqdaycount ='7')
Update Extracts..Processlastruns
Set Proclastrunsystemdate =@RunDate , proclastwritesystemdate =@RunDate
Where Procrunid in(select Procrunid From Extracts..Processruns Where Procrunenabled ='1' and Procrunfreqdaycount ='1')


I use that query but it isn't working. I'm catching "Unexpected argument"

sqlcmd -S 192.168.0.1 -U sa -P test1234
"Use Extracts DECLARE @RunDate DATETIME; DECLARE @WeeklyRunDate DATETIME; SET @RunDate = '2016/08/31' SET @WeeklyRunDate = (select DATEADD(dd, -(DATEPART(dw, @RunDate)-1), @RunDate)) Update Extracts..Processlastruns Set Proclastrunsystemdate =@WeeklyRunDate , proclastwritesystemdate =@WeeklyRunDate Where Procrunid in(select Procrunid From Extracts..Processruns Where Procrunenabled ='1' and Procrunfreqdaycount ='7') Update Extracts..Processlastruns Set Proclastrunsystemdate =@RunDate proclastwritesystemdate =@RunDate Where Procrunid in(select Procrunid From Extracts..Processruns Where Procrunenabled ='1' and Procrunfreqdaycount ='1')" -o extract.csv -s"," -w 700

Answer

Please try to add the switch -Q Microsoft sqlcmd Utility

sqlcmd -S 192.168.0.1 -U sa -P test1234 -Q "your SQL" -o extract.csv -s"," -w 700