Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet126/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   122   123   124   125   126   127   128   129   ...   443
Bog'liq
BookSQL

Filtering date ranges

When you need to filter a range of dates, such as a whole year or a whole month, it seems natural to 

use functions such as YEAR and MONTH. For example, the following query returns all orders placed in 

the year 2007.

SELECT orderid, custid, empid, orderdate 

FROM Sales.Orders 

WHERE YEAR(orderdate) = 2007;

However, you should be aware that in most cases, when you apply manipulation on the filtered 

column, SQL Server cannot use an index in an efficient manner. This is probably hard to understand 

without some background about indexes and performance, which are outside the scope of this book, 

but for now, just keep this general point in mind: To have the potential to use an index efficiently, you 

need to revise the predicate so that there is no manipulation on the filtered column, like this. 

SELECT orderid, custid, empid, orderdate 

FROM Sales.Orders 

WHERE orderdate >= '20070101' AND orderdate < '20080101';

Similarly, instead of using functions to filter orders placed in a particular month, like this:

SELECT orderid, custid, empid, orderdate 

FROM Sales.Orders 

WHERE YEAR(orderdate) = 2007 AND MONTH(orderdate) = 2;

use a range filter, like the following.

SELECT orderid, custid, empid, orderdate 

FROM Sales.Orders 

WHERE orderdate >= '20070201' AND orderdate < '20070301';

www.it-ebooks.info




80  

Microsoft SQL Server 2012 T-SQL Fundamentals




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   122   123   124   125   126   127   128   129   ...   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