更新表格变量时出现问题。我已经声明了它,但是当我运行整个查询时,我得到了这个错误:



而且我似乎无法解决问题...

UPDATE @List
SET nrID = CASE
              WHEN nrID IS NULL
                 THEN t1.nrID
                 ELSE nrID
           END
FROM @List
INNER JOIN table1 t1 ON @List.PNr = t1.PNr
INNER JOIN table2 t2 ON t1.n nrPNr = t2.nrPNr
WHERE t1.PNr = t2.PNr AND t2.Isactive = 0

最佳答案

UPDATE List
SET List.nrID = t1.nrID
FROM @List AS List
INNER JOIN table1 t1 ON List.nrID = t1.nrID
INNER JOIN table2 t2 ON t1.nrID = t2.nrID
WHERE t1.nrID = t2.nrID AND t2.Isactive = 0

如评论中所述,内部联接将删除您情况下的所有空值

关于sql - '.'附近的语法不正确。在更新变量表时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39372137/

10-11 01:55