troubleshooting Question

SQL SERVER SCRIPT - NESTED IF STATEMENTS

Avatar of cbridgman
cbridgmanFlag for United States of America asked on
Microsoft SQL ServerSQL
4 Comments3 Solutions220 ViewsLast Modified:
I am attempting to figure out a SQL script and am unclear how nested IF statements behave. An example of what I am trying to figure out is shown below. Assuming that the 1st IF statement is true (A='22222'), does the last IF statement (IF D = 'ORTGNV')  get evaluated regardless of the answer to the second IF statement (IF B='12345' and C='98765')? I've also attached a word copy of the script in case indentation is messed up.

IF A = ‘22222’
      BEGIN
            DO AAA
            IF B = ‘12345’ and C = ‘98765’
                  BEGIN
                        DO BBB
                  END
            ELSE
                  BEGIN
                        DO CCC
                  END
            IF D = ‘ORTGNV’
                  BEGIN
                        DO DDD
                  END
END
SQL-Script-Nested-IF.docx
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 3 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros