多个数据库中的sqlcmd查询"Unexpected argument"

Sqlcmd query in mutliple database "Unexpected argument"

我有一个 SQL 查询,我需要通过一个请求在多个实例上 运行。

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')

我使用了那个查询,但它不起作用。我在抓"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

更改更新提取..Processlastruns 更新Extracts.Processlastruns, 还有一些地方你的查询有 '..' in table prefix

请尝试添加开关-QMicrosoft sqlcmd Utility

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