如果存储过程允许处理复合条件,请告诉我:
if(
( (select Count(*) from dbo.Membership where EmailID=@emailID) >0)
||
((select Count(*) from dbo.Allocation where ResourceEmail=@emailID)>0))
)
答案 0 :(得分:5)
使用OR
代替||
如果只是检查是否存在,那么我会使用EXISTS代替COUNT,因为它会在它第一次存在时停止,而不是全部计算...
IF EXISTS(SELECT 1 FROM dbo.Membership WHERE EmailId = @emailID)
OR EXISTS(SELECT 1 FROM dbo.Allocation where ResourceEmail=@emailID)
BEGIN
-- emailID exists in one of the 2 tables
END