<bdo id='f1fY6'></bdo><ul id='f1fY6'></ul>

        <legend id='f1fY6'><style id='f1fY6'><dir id='f1fY6'><q id='f1fY6'></q></dir></style></legend><tfoot id='f1fY6'></tfoot>
        <i id='f1fY6'><tr id='f1fY6'><dt id='f1fY6'><q id='f1fY6'><span id='f1fY6'><b id='f1fY6'><form id='f1fY6'><ins id='f1fY6'></ins><ul id='f1fY6'></ul><sub id='f1fY6'></sub></form><legend id='f1fY6'></legend><bdo id='f1fY6'><pre id='f1fY6'><center id='f1fY6'></center></pre></bdo></b><th id='f1fY6'></th></span></q></dt></tr></i><div id='f1fY6'><tfoot id='f1fY6'></tfoot><dl id='f1fY6'><fieldset id='f1fY6'></fieldset></dl></div>

        <small id='f1fY6'></small><noframes id='f1fY6'>

        在 SQL Server 2008 中执行 while 循环

        时间:2023-10-10
      1. <tfoot id='DVQ4Q'></tfoot>

          <legend id='DVQ4Q'><style id='DVQ4Q'><dir id='DVQ4Q'><q id='DVQ4Q'></q></dir></style></legend>

              <i id='DVQ4Q'><tr id='DVQ4Q'><dt id='DVQ4Q'><q id='DVQ4Q'><span id='DVQ4Q'><b id='DVQ4Q'><form id='DVQ4Q'><ins id='DVQ4Q'></ins><ul id='DVQ4Q'></ul><sub id='DVQ4Q'></sub></form><legend id='DVQ4Q'></legend><bdo id='DVQ4Q'><pre id='DVQ4Q'><center id='DVQ4Q'></center></pre></bdo></b><th id='DVQ4Q'></th></span></q></dt></tr></i><div id='DVQ4Q'><tfoot id='DVQ4Q'></tfoot><dl id='DVQ4Q'><fieldset id='DVQ4Q'></fieldset></dl></div>
                  <bdo id='DVQ4Q'></bdo><ul id='DVQ4Q'></ul>

                  <small id='DVQ4Q'></small><noframes id='DVQ4Q'>

                    <tbody id='DVQ4Q'></tbody>
                  本文介绍了在 SQL Server 2008 中执行 while 循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  SQL server 2008有没有实现do while循环的方法?

                  解决方案

                  我不确定 MS SQL Server 2008 中的 DO-WHILE,但您可以更改 WHILE 循环逻辑,以便像 DO-WHILE 循环一样使用.

                  示例取自此处:http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/

                  <块引用>

                  1. WHILE 循环示例

                    DECLARE @intFlag INT设置@intFlag = 1同时 (@intFlag <=5)开始打印@intFlagSET @intFlag = @intFlag + 1结尾走

                    结果集:

                    12345

                  2. 带有 BREAK 关键字的 WHILE 循环示例

                    DECLARE @intFlag INT设置@intFlag = 1同时 (@intFlag <=5)开始打印@intFlagSET @intFlag = @intFlag + 1如果@intFlag = 4休息;结尾走

                    结果集:

                    123

                  3. 带有 CONTINUE 和 BREAK 关键字的 WHILE 循环示例

                    DECLARE @intFlag INT设置@intFlag = 1同时 (@intFlag <=5)开始打印@intFlagSET @intFlag = @intFlag + 1继续;IF @intFlag = 4 -- 这将永远不会执行休息;结尾走

                    结果集:

                    12345

                  但是尽量在数据库级别避免循环.参考.

                  Is there any method for implement do while loop in SQL server 2008?

                  解决方案

                  I am not sure about DO-WHILE IN MS SQL Server 2008 but you can change your WHILE loop logic, so as to USE like DO-WHILE loop.

                  Examples are taken from here: http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/

                  1. Example of WHILE Loop

                    DECLARE @intFlag INT
                    SET @intFlag = 1
                    WHILE (@intFlag <=5)
                    BEGIN
                        PRINT @intFlag
                        SET @intFlag = @intFlag + 1
                    END
                    GO
                    

                    ResultSet:

                    1
                    2
                    3
                    4
                    5
                    

                  2. Example of WHILE Loop with BREAK keyword

                    DECLARE @intFlag INT
                    SET @intFlag = 1
                    WHILE (@intFlag <=5)
                    BEGIN
                        PRINT @intFlag
                        SET @intFlag = @intFlag + 1
                        IF @intFlag = 4
                            BREAK;
                    END
                    GO
                    

                    ResultSet:

                    1
                    2
                    3
                    

                  3. Example of WHILE Loop with CONTINUE and BREAK keywords

                    DECLARE @intFlag INT
                    SET @intFlag = 1
                    WHILE (@intFlag <=5)
                    BEGIN
                        PRINT @intFlag
                        SET @intFlag = @intFlag + 1
                        CONTINUE;
                        IF @intFlag = 4 -- This will never executed
                            BREAK;
                    END
                    GO
                    

                    ResultSet:

                    1
                    2
                    3
                    4
                    5
                    

                  But try to avoid loops at database level. Reference.

                  这篇关于在 SQL Server 2008 中执行 while 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 MySQL 中循环结果集 下一篇:SQL Server 中 for 循环的语法

                  相关文章

                  1. <tfoot id='FaHk8'></tfoot>

                    <i id='FaHk8'><tr id='FaHk8'><dt id='FaHk8'><q id='FaHk8'><span id='FaHk8'><b id='FaHk8'><form id='FaHk8'><ins id='FaHk8'></ins><ul id='FaHk8'></ul><sub id='FaHk8'></sub></form><legend id='FaHk8'></legend><bdo id='FaHk8'><pre id='FaHk8'><center id='FaHk8'></center></pre></bdo></b><th id='FaHk8'></th></span></q></dt></tr></i><div id='FaHk8'><tfoot id='FaHk8'></tfoot><dl id='FaHk8'><fieldset id='FaHk8'></fieldset></dl></div>
                    • <bdo id='FaHk8'></bdo><ul id='FaHk8'></ul>

                    1. <legend id='FaHk8'><style id='FaHk8'><dir id='FaHk8'><q id='FaHk8'></q></dir></style></legend>
                    2. <small id='FaHk8'></small><noframes id='FaHk8'>