Bird
0
0

What is wrong with this SQL procedure snippet?

medium📝 Debug Q7 of 15
SQL - Stored Procedures and Functions
What is wrong with this SQL procedure snippet?
DECLARE @counter INT = 0;
WHILE @counter < 3
BEGIN
SET @counter = @counter + 1;
END
PRINT @counter;
APRINT statement is outside BEGIN...END block
BNo PRINT statement inside loop to show progress
CNo syntax error; code runs and prints 3
DVariable @counter is not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop and variable initialization

    @counter starts at 0, increments to 3 correctly.
  2. Step 2: Check PRINT statement placement

    PRINT after loop is valid and prints final value 3.
  3. Final Answer:

    No syntax error; code runs and prints 3 -> Option C
  4. Quick Check:

    Code runs fine and prints final counter [OK]
Quick Trick: PRINT can be outside loop; no error if variable initialized [OK]
Common Mistakes:
  • Thinking PRINT must be inside loop
  • Assuming variable uninitialized
  • Confusing syntax with logic errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes