1

也许我缺少一个括号或其他东西,但我很难从我要加入的表变量中删除行并寻找我要加入的键。如果它有价值,那么我就摆脱它。问题是我无法解析查询。有任何想法吗?

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
4

3 回答 3

2
DELETE @MrTemp
FROM @MrTemp mt LEFT JOIN ...
于 2009-03-31T16:09:40.820 回答
1

您需要在删除之后但在要从中删除的表的 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
于 2009-03-31T16:09:50.993 回答
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

或者。从 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
于 2009-03-31T16:15:58.810 回答