Bird
0
0

What will be the output of the following SQL procedure snippet?

medium📝 query result Q4 of 15
SQL - Stored Procedures and Functions
What will be the output of the following SQL procedure snippet?
DECLARE @num INT = 2;
WHILE @num <= 4
BEGIN
PRINT @num;
SET @num = @num + 1;
END
A1 2 3 4
B2 3 4
C2 3 4 5
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Initialize variable

    @num starts at 2.
  2. Step 2: Loop condition

    Loop runs while @num <= 4.
  3. Step 3: Loop iterations

    Prints 2, increments to 3; prints 3, increments to 4; prints 4, increments to 5; loop ends.
  4. Final Answer:

    2 3 4 -> Option B
  5. Quick Check:

    Loop prints values from 2 to 4 inclusive [OK]
Quick Trick: Loop prints from start to end value inclusive [OK]
Common Mistakes:
  • Assuming loop starts at 1 instead of 2
  • Including the value after loop ends (5)
  • Thinking no output occurs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes