Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet98/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   94   95   96   97   98   99   100   101   ...   443
Bog'liq
BookSQL

 

CHAPTER 2

 

Single-Table Queries



 

 55

10255       68          2490.50  Between 1000 and 3000 

10256       88          517.80   Less than 1000 

10257       35          1119.90  Between 1000 and 3000 

... 

 

(830 row(s) affected)



You can see that every simple CASE expression can be converted to the searched CASE form, but 

the reverse is not necessarily true.

T-SQL supports some functions that you can consider as abbreviations of the CASE expression: 

ISNULLCOALESCEIIF, and CHOOSE. Note that of the four, only COALESCE is standard. Also, IIF and 

CHOOSE are available only in SQL Server 2012.

The ISNULL function accepts two arguments as input and returns the first that is not NULL, or NULL 

if both are NULL. For example ISNULL(col1, ‘’) returns the col1 value if it isn’t NULL, and an empty string 

if it is NULL. The COALESCE function is similar, only it supports two or more arguments and returns 

the first that isn’t NULL, or NULL if all are NULL. As mentioned earlier, when there’s a choice, it is 

generally recommended that you use standard features, hence it is recommended that you use the 



COALESCE function and not ISNULL.

The nonstandard IIF and CHOOSE functions were added in SQL Server 2012 to support easier 

migrations from Microsoft Access. The function IIF() returns 

expr1 if logical_expression is TRUE and expr2 otherwise. For example, the expression IIF(col2 <> 0, 

col2/col1, NULL) returns the result of col2/col1 if col1 is not zero, otherwise it returns a NULL. The 

function CHOOSE(, …, ) returns the expression from the list in the 

specified index. For example, the expression CHOOSE(3, col1, col2, col3) returns the value of col3. Of 

course, actual expressions that use the CHOOSE function tend to be more dynamic—for example, 

relying on user input.

So far, I’ve just used a few examples to familiarize you with the CASE expression and functions that 

can be considered abbreviations of the CASE expression. Even though it might not be apparent at this 

point from these examples, the CASE expression is an extremely powerful and useful language element.




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   94   95   96   97   98   99   100   101   ...   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