Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If Exist or Exists?

Is it possible to test two EXISTS conditions in a single IF SQL statement? I've tried the following.

IF EXIST (SELECT * FROM tblOne WHERE field1 = @parm1 AND field2 = @parm2) 
   OR 
   EXIST (SELECT * FROM tblTwo WHERE field1 = @parm5 AND field2 = @parm3) 

I've tried playing with adding additional IF and parenthesis in there, but to no avail.

Can you help me out with the proper syntax?

like image 548
user1142433 Avatar asked Jan 11 '13 20:01

user1142433


People also ask

Is it there exist or there exists?

You can use “there exist” when speaking of a non-singular amount or number of things. For example, “There exist several animals which have stripes on their hides.” You use “There exists” when speaking of a singular item or a single group of items.

Does not exist or exists?

The right form is: The file doeSn't exist. Gramatical explanation: always when you're forming a positive sentence about a 3rd person (singular only) in present simple tense, you have to add the letter s to the verb which describeS what he doeS.

Is already exist or already exists?

A complete search of the internet has found these results: already exists is the most popular phrase on the web. More popular!


2 Answers

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.

like image 192
Martin Smith Avatar answered Nov 02 '22 23:11

Martin Smith


You missed an S at the end of EXIST

EXISTS, not EXIST

like image 22
alexb Avatar answered Nov 03 '22 00:11

alexb