为不存在的每个项调用存储过程

时间:2014-03-14 08:38:48

标签: sql sql-server loops stored-procedures cursor

我有以下

delete from Listing
where not exists
(
   select 1
   from ComparitiveListings
   where Listing.ListingKey = ComparitiveListings.ListingKey
 )

但我真正想做的是为表MySprocListingKey的每个LISTING执行一个存储过程COMPARITIVELISTINGS,该存储过程在列ListingKey列中找不到{1}}。

我认为必须有光标的方法,但我不确定?有人在这吗?

1 个答案:

答案 0 :(得分:1)

Create proc myProc
As
BEGIN
delete from Listing
    where ListingKey not in
    (
       select ListingKey
       from ComparitiveListings

     )
END