Update table1 t1
set t1. col1='op'
where t1.col2 in (select t2.col2 from table2 t2 where t1.col3 = t2.col3) ;
上述查询在 Oracle 中有效,但在 SQL Server 中无效。
抛出错误:t1 附近的语法不正确。
不能UPDATE
在 SQL Server的子句中设置别名。正确的语法是删除别名或别名中的对象FROM
:
--Without Alias
UPDATE table1
SET col1 = 'op'
WHERE EXISTS (SELECT 1
FROM Table2 AS T2
WHERE T2.col3 = table1.col3
AND T2.col2 = table1.col2);
--FROM and JOIN
UPDATE T1
SET col1 = 'op'
FROM Table1 AS T1
JOIN Table2 AS T2 ON T1.Col2 = T2.Col2
AND T1.Col3 = T2.Col3;
--With Aliases
UPDATE T1
SET col1 = 'op'
FROM Table1 AS T1
WHERE EXISTS (SELECT 1
FROM Table2 AS T2
WHERE T2.col3 = table1.col3
AND T2.col2 = table1.col2);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句