Sql server® 2012 t-sql fundamentals



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

The 

WHILE

 Flow element

T-SQL provides the WHILE element to enable you to execute code in a loop. The WHILE element 

executes a statement or statement block repeatedly while the predicate you specify after the WHILE 

keyword is TRUE. When the predicate is FALSE or UNKNOWN, the loop terminates.

T-SQL doesn’t provide a built-in looping element that executes a predetermined number of times, 

but it’s very easy to mimic such an element with a WHILE loop and a variable. For example, the fol-

lowing code demonstrates how to write a loop that iterates 10 times.

DECLARE @i AS INT = 1; 

WHILE @i <= 10 

BEGIN 


  PRINT @i; 

  SET @i = @i + 1; 

END;

The code declares an integer variable called @i that serves as the loop counter and initializes it 



with the value 1. The code then enters a loop that iterates while the variable is smaller than or equal 

to 10. In each iteration, the code in the loop’s body prints the current value of @i and then increments 

it by 1. This code returns the following output showing that the loop iterated 10 times.

www.it-ebooks.info





Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   376   377   378   379   380   381   382   383   ...   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