Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Logical short circuits in queries?
Message
From
09/08/2004 20:16:44
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Logical short circuits in queries?
Miscellaneous
Thread ID:
00931921
Message ID:
00931921
Views:
54
I am not experienced with SQL, but I have a basic understanding.

I want to determine if a value exists in any of a set of tables. I want to stop after I find the first instance. The pseudocode for a simplified case would be,

IF EXISTS
  (SELECT TOP 1 field1
   FROM table1
   WHERE field1 = myValue)
THEN
   RETURN true
ELSE IF EXISTS
  (SELECT TOP 1 field2
   FROM table2
   WHERE field2 = myValue)
THEN
  RETURN true
ELSE
  RETURN false
END IF
I eventually need this to be in a stored procedure. I have to believe that only querying the minimum necessary tables is more efficient than unioning a couple the separate queries.
David S. Alexander
Kettley Publishing
20271 SW Birch Street, 2nd Floor
Newport Beach, CA 92660-1752
Next
Reply
Map
View

Click here to load this message in the networking platform