关键字“set”和“as”附近的语法不正确

时间:2013-12-06 15:10:58

标签: sql-server sql-server-2008 tsql

您好我的mssql代码中出现异常。这是一个例外:

Incorrect syntax near the keyword 'set' and 'as'.

这是我的sql代码:

UPDATE SET TBLSurvey.Status=-1  FROM TBLSurvey
RIGHT JOIN (
SELECT  OrderId
FROM [CRM_NEW].[dbo].[TBLSurvey]
GROUP BY OrderId HAVING(COUNT(*)>1)) AS sd ON TBLSurvey.OrderID=sd.OrderId
WHERE AnswerDate IS NULL AND Status=0‏

不知道。

2 个答案:

答案 0 :(得分:3)

在SQL Server中,应该开始更新:

update TBLSurvey
    set Status = -1
    from TBLSurvey . . .

SQL Server中update的语法是here。如果我不得不猜测,看起来你对MySQL语法的各个方面感到困惑。

答案 1 :(得分:2)

也许你的意思是:

UPDATE t
  SET [Status] = -1
  FROM dbo.TBLSurvey AS t
  WHERE [Status] = 0
  AND NOT EXISTS
  (
    SELECT 1 FROM CRM_NEW.dbo.TBLSurvey
    WHERE OrderId = t.OrderId
    GROUP BY OrderId HAVING COUNT(*) > 1
  ) AS sd;