在mutliple数据库中进行Sqlcmd查询"意外的参数"

时间:2016-09-14 09:14:33

标签: sql sql-server sqlcmd

我有一个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')

我使用该查询但它不起作用。我抓住了#34;意想不到的争论"

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

2 个答案:

答案 0 :(得分:0)

更改更新提取...过程更新Extracts.Processlastruns, 还有一些地方,您的查询在表格前缀

中有'..'

答案 1 :(得分:0)

请尝试添加开关-Q Microsoft sqlcmd Utility

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