BREAK stops the execution of the statements inside the block : Break « Transact SQL « SQL Server / T-SQL






BREAK stops the execution of the statements inside the block

1>
2> CREATE TABLE project   (project_no   CHAR(4) NOT NULL,
3>                         project_name CHAR(15) NOT NULL,
4>                         budget FLOAT NULL)
5>
6> insert into project values ('p1', 'Search Engine',        120000.00)
7> insert into project values ('p2', 'Programming',          95000.00)
8> insert into project values ('p3', 'SQL',                  186500.00)
9>
10> select * from project
11> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)
project_no project_name    budget
---------- --------------- ------------------------
p1         Search Engine                     120000
p2         Programming                        95000
p3         SQL                               186500

(3 rows affected)
1>
2> --BREAK stops the execution of the statements inside the block
3>
4>
5> WHILE (SELECT SUM(budget) FROM project) < 500000
6> BEGIN
7>      UPDATE project SET budget = budget*1.1
8>         IF (SELECT MAX(budget) FROM project) > 240000
9>             BREAK
10>         ELSE
11>             CONTINUE
12> END
13>
14> select * from project
15> GO

(3 rows affected)

(3 rows affected)

(3 rows affected)
project_no project_name    budget
---------- --------------- ------------------------
p1         Search Engine                     159720
p2         Programming           126445.00000000004
p3         SQL                   248231.50000000009

(3 rows affected)
1>
2> drop table project
3> GO
1>
2>

           
       








Related examples in the same category

1.BREAK exits the WHILE structure, resuming execution after the END statement