If Exist or Exists? If Exist or Exists? sql-server sql-server

If Exist or Exists?


If SQL Server

IF EXISTS (SELECT *           FROM   tblOne           WHERE  field1 = @parm1                  AND field2 = @parm2)    OR EXISTS (SELECT *               FROM   tblTwo               WHERE  field1 = @parm5                      AND field2 = @parm3)  PRINT 'YES' 

Is fine, note the only thing changed is EXISTS not EXIST. The plan for this will probably be a UNION ALL that short circuits if the first one tested is true.


You missed an S at the end of EXIST

EXISTS, not EXIST


You could also write an IN statement

IF EXISTS (SELECT * FROM tblOne WHERE field1 = @parm1 AND field2 IN (@parm2,@parm3)