在existing语句中使用表变量 [英] Using a table variable inside of a exists statement
本文介绍了在existing语句中使用表变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据条件更新表变量内的列,条件是该表变量的ID在其他表中不存在:
I am trying to update a column inside of a table variable based on a condition, the condition being that the ID of the table variable does not exist in a different table:
DECLARE @BugRep TABLE(BugCode VARCHAR(50),DevFirstName VARCHAR(50), DevLastName VARCHAR(50), BugDate VARCHAR(20), IsValid VARCHAR(1))
UPDATE @BugRep
SET IsValid = 'N' WHERE NOT EXISTS(SELECT * FROM BUG b WHERE @BugRep.BUGCODE = b.CODE)
当我尝试编译具有这些语句的过程时,我收到必须声明标量变量"@BugRep"消息.
When i try to compile the procedure that has these statements, I get a "Must declare the scalar variable "@BugRep" message.
如何在NOT EXISTS子句中使用表变量?
How do i go about using the table variable inside of the NOT EXISTS clause?
我正在使用SQL Server 2008
I am using SQL Server 2008
推荐答案
这将起作用:
[@BugRep].BUGCODE
您还需要将"b.CODE"更改为"b.BUGCODE";)
You'll also need to change "b.CODE" to "b.BUGCODE" by the way ;)
这篇关于在existing语句中使用表变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文