也许我错过了一个支架或者其他东西,但是我很难从表格变量中删除行,而我正在加入并寻找我正在加入的密钥。如果它有一个值,那么我就摆脱它了。问题是我无法解析查询。有什么想法吗?
声明@MrTemp ( key1 int ,key2 int )
插入@MrTemp 从ASourceTable中选择key1,key2
删除
来自@MrTemp山
在mt.key1 = art.key1和mt.key2 = art.key2上左连接ARealTable art
其中art.key1不为null且art.key2不为null
答案 0 :(得分:2)
DELETE @MrTemp
FROM @MrTemp mt LEFT JOIN ...
答案 1 :(得分:1)
您一次只能从一个表中删除:
从@MrTemp中删除[其中ARealTable中有匹配的记录]
delete mt
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 nu
LL
或。 从ARealTable中删除[再次记录在ARealTable中有相应的记录]
delete art
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
答案 2 :(得分:0)
您需要在删除后但在要从
删除的表的from之前引用别名delete art
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