更新时间:2023-02-06 08:28:50
你必须看WHILE语句的声明:
You must look at declaration of WHILE statement:
WHILE Boolean_expression
{ sql_statement | statement_block | BREAK | CONTINUE }
首先,你可以像 Dan 所说的那样使用复杂的 Boolean_expression:
First of all you can use complex Boolean_expression as Dan said:
WHILE @N > -1 AND @N <10
BEGIN
END
如果您想为代码添加更多灵活性,可以使用 IF 与 BREAK,类似这样:
If you want to add more flexibility to you code you can use IF with BREAK, something like this:
WHILE @N > -1 AND @N <10
BEGIN
-- code
IF (SELECT MAX(ListPrice) FROM Production.Product) > $500
BREAK
END
-- code
END
退出循环或使用 CONTINUE 跳过一个循环.
to go out of cycle or use CONTINUE to skip one cycle.