This question already has an answer here:
这个问题在这里已有答案:
- How to fix “Must declare the scalar variable” error when referencing table variable? 1 answer
- 如何在引用表变量时修复“必须声明标量变量”错误? 1个答案
I am trying to do:
我想做:
update existingTable
set code = @declaredTable.code
where id = @declaredTable.id
but when I do this I get the error:
但是当我这样做时,我得到错误:
Must declare the scalar variable "@declaredTable"
必须声明标量变量“@declaredTable”
twice.
两次。
How do I update values of an existing tables to values from a declared tables?
如何将现有表的值更新为声明表中的值?
Why doesn't this work?
为什么这不起作用?
Any help would be much appreciated!
任何帮助将非常感激!
1 个解决方案
#1
3
You need JOIN
:
你需要加入:
UPDATE e
SET e.code = d.code
FROM existingTable e INNER JOIN
@declaredTable d
on d.id = e.id;
#1
3
You need JOIN
:
你需要加入:
UPDATE e
SET e.code = d.code
FROM existingTable e INNER JOIN
@declaredTable d
on d.id = e.id;