Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet381/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   377   378   379   380   381   382   383   384   ...   443
Bog'liq
BookSQL

 

CHAPTER 10

 

Programmable Objects



 

 347







10

If at some point in the loop’s body you want to break out of the current loop and proceed to exe-



cute the statement that appears after the loop’s body, use the BREAK command. For example, the 

following code breaks from the loop if the value of @i is equal to 6.

DECLARE @i AS INT = 1; 

WHILE @i <= 10 

BEGIN 

  IF @i = 6 BREAK; 



  PRINT @i; 

  SET @i = @i + 1; 

END;

This code produces the following output showing that the loop iterated five times and terminated 



at the beginning of the sixth iteration.



5



Of course, this code is not very sensible; if you want the loop to iterate only five times, you should 

simply specify the predicate @i <= 5. Here I just wanted to demonstrate the use of the BREAK com-

mand with a simple example.

If at some point in the loop’s body you want to skip the rest of the activity in the current iteration 

and evaluate the loop’s predicate again, use the CONTINUE command. For example, the following 

code demonstrates how to skip the activity of the sixth iteration of the loop from the point where the 



IF statement appears and until the end of the loop’s body.

DECLARE @i AS INT = 0; 

WHILE @i < 10 

BEGIN 


  SET @i = @i + 1; 

  IF @i = 6 CONTINUE; 

  PRINT @i; 

END;


www.it-ebooks.info


348  

Microsoft SQL Server 2012 T-SQL Fundamentals

The output of this code shows that the value of @i was printed in all iterations but the sixth.







10


Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   377   378   379   380   381   382   383   384   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish