create proc pro_A(
@clmA  nvarchar(20),
@clmB  nvarchar(20),
@clmC  nvarchar(20))
--@clmC 的值可以传过来空串(''),就是下面的查询操作可以有它,如果是空串就不要它
AS
 if exists(select ID from tblA where clmA=@clmA and clmB=@clmB and (@clmC is null or len(@clmC)=0 or clmC=@clmC ))
 begin 
select 1
 ----------........
 end
delete from tblB where tblB.ID in (select ID from tblA where clmA=@clmA and clmB=@clmB and (@clmC is null or len(@clmC)=0 or clmC=@clmC ))

解决方案 »

  1.   

    select count(ID) from tblA where clmA=@clmA and clmB=@clmB if(execute(查询语句))〉0
         begin 
         ----------........
         end
      

  2.   

    if(exists(select ID from tblA where clmA=@clmA and clmB=@clmB and clmC=(case when len(@clmC)=0 then clmC else @clmC end))
         begin 
         ----------........
         end
        delete from tblB where tblB.ID in (select ID from tblA where clmA=@clmA and clmB=@clmB and clmC=(case when len(@clmC)=0 then clmC else @clmC end))