Sql server® 2012 t-sql fundamentals


dealing with Misbehaving Subqueries



Download 10,93 Mb.
Pdf ko'rish
bet198/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   194   195   196   197   198   199   200   201   ...   443
Bog'liq
BookSQL

dealing with Misbehaving Subqueries

This section introduces cases in which subqueries might behave counter to your expectations, and 

provides best practices that you can follow to avoid logical bugs in your code that are associated with 

those cases.



NULL

 Trouble

Remember that T-SQL uses three-valued logic. In this section, I will demonstrate problems that can 

evolve with subqueries when NULL marks are involved and you do not take into consideration the 

three-valued logic.

Consider the following apparently intuitive query that is supposed to return customers who did 

not place orders. 

SELECT custid, companyname 

FROM Sales.Customers 

WHERE custid NOT IN(SELECT O.custid 

                    FROM Sales.Orders AS O);

With the current sample data in the Orders table in the TSQL2012 database, the query seems to 

work the way you expect it to; and indeed, it returns two rows for the two customers who did not 

place orders.

custid      companyname 

----------- ---------------- 

22          Customer DTDMN 

57          Customer WVAXS 

www.it-ebooks.info





Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   194   195   196   197   198   199   200   201   ...   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