Database Reference
In-Depth Information
Table 7.1
Flow-Control Keywords and Descriptions
Keyword
Description
WHILE
It deines a loop structure. A block of SQL statements within
the loop structure will be executed repeatedly while a given
condition continues to be met.
BEGIN. . .END
It deines a block of SQL statements.
BREAK
While a given condition is met, exit a WHILE loop. For
embedded WHILE loops, exit the innermost WHILE loop irst.
CONTINUE
When a given condition is met, continue the executions in a
WHILE loop.
IF. . .ELSE
When the IF condition is met, the block of SQL statements
under the IF clause is executed. Otherwise, the block of SQL
statements under the ELSE clause is executed.
RETURN
Exit the processing of the SQL statements unconditionally and
return to the calling program.
GOTO label
Jump to the SQL statement labeled by the keyword label and
continue to process other SQL statements from there.
WAITFOR
Delay a statement execution until a speciied time.
the same day. If so, the class with a larger id number will be moved to the next day. he following
are the SQL statements that can be used to accomplish the task:
Declare @Count INT
SET @Count = 1
WHILE (@Count < 5)
BEGIN
IF (@Count = 1)
BEGIN
UPDATE CLASS
SET DayID = DayID + 1
WHERE DayID = 1
END
ELSE
BEGIN
UPDATE CLASS
SET DayID = DayID + 1
WHERE ClassID = (SELECT MAX(ClassID)
FROM CLASS
WHERE CourseID IN (SELECT CourseID
FROM CLASS
GROUP BY CourseID, DayID
HAVING COUNT(CourseID) > 1))
END
SET @Count = @Count + 1
END
Search WWH ::




Custom Search