使用左连接和表变量进行删除
也许我缺少括号或其他东西,但我很难从表变量中删除行,我在其中加入并寻找要加入的键。 如果它有价值,那么我就会摆脱它。 问题是我无法解析查询。 有任何想法吗?
declare @MrTemp
(
key1 int
,key2 int
)
insert into @MrTemp
select key1, key2 from ASourceTable
delete
from @MrTemp mt
left join ARealTable art on mt.key1 = art.key1 and mt.key2 = art.key2
where art.key1 is not null and art.key2 is not null
Maybe I'm missing a bracket or something but I'm having a hard time deleting rows from a table variable where I'm left joining and looking for the key I'm joining on. If it has a value, then I get rid of it. The problem is that I can't get the query to parse. Any ideas?
declare @MrTemp
(
key1 int
,key2 int
)
insert into @MrTemp
select key1, key2 from ASourceTable
delete
from @MrTemp mt
left join ARealTable art on mt.key1 = art.key1 and mt.key2 = art.key2
where art.key1 is not null and art.key2 is not null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在删除之后但在要从中删除的表的 from 之前引用别名
You need to reference the alias after the delete but before the from for the table you want to delete from
您一次只能从一个表中删除:
从 @MrTemp [ARealTable 中有匹配记录]
ll
或删除。
从 ARealTable 中删除 [同样,该记录在 ARealTable 中有对应的记录]
You can only delete from one table at a time:
to delete from @MrTemp [where there is a matching record in ARealTable]
ll
or.
to delete from ARealTable [again where the record has a corresponding record in ARealTable]