Yag*_*rma 0 t-sql sql-server-2008
如果存储过程允许处理复合条件,请告诉我:
if(
( (select Count(*) from dbo.Membership where EmailID=@emailID) >0)
||
((select Count(*) from dbo.Allocation where ResourceEmail=@emailID)>0))
)
Run Code Online (Sandbox Code Playgroud)
用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
Run Code Online (Sandbox Code Playgroud)