Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE Statement - Excecution Flow Explanation 1

Status
Not open for further replies.

eb24

Programmer
Dec 17, 2003
240
US
I would like to know the execution flow of a CASE statement. As the code processes, if a field gets updated, then is it left out of the rest of the flow, or let's say it meets criteria #1 and then later it meets criteria #3 as well? I just want my code once it meets the first criteria, to assign it that value. Thus, something like a precedence. If first criteria, that's it. If it meets two criteria, just pick the first (higher precedences). I don't want it to meet criteria #1 and then be overriden by the last flow statement which is low precedence. Or should I choose another flow statement to implement?

Let's say I have a CASE statement that UPDATES a certain table and with three conditions, e.g.:
Code:
UPDATE Table_Report
SET Field1 =
   CASE 
      WHEN Field2 IN (SELECT E.EMP_PKEY FROM   Table_Employee E INNER JOIN Table_Audit Q ON E.EMP_PKEY = Q.EMP_KEY INNER JOIN Table_Users T ON E.EMP_ID = T.EMPLID
      WHERE (E.EMP_ID = '123456') OR
         (E.EMP_ID = '100123') THEN 1
      WHEN Field2 IN (SELECT E.EMP_PKEY FROM   Table_Employee E INNER JOIN Table_Audit Q ON E.EMP_PKEY = Q.EMP_KEY INNER JOIN Table_Users T ON E.EMP_ID = T.EMPLID
      WHERE (T.LOCATION = 'CALIFORNIA')) THEN 2
      WHEN Field3 LIKE '%terminated%' THEN 3
END
WHERE Field1 IS NULL
Any feedback will be greatly appreciated!
 
As soon as it meets a condition that's true, it gets out of the case statement for the row that is processing.
 
PruSQLer:

That is the answer I was hoping for! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top