Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet216/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   212   213   214   215   216   217   218   219   ...   443
Bog'liq
BookSQL

Common Table Expressions

Common table expressions (CTEs) are another standard form of table expression very similar to de-

rived tables, yet with a couple of important advantages. 

CTEs are defined by using a WITH statement and have the following general form.

WITH [()] 

AS 


   



;

The inner query defining the CTE must follow all requirements mentioned earlier to be valid to 

define a table expression. As a simple example, the following code defines a CTE called USACusts 

based on a query that returns all customers from the United States, and the outer query selects all 

rows from the CTE.

WITH USACusts AS 

  SELECT custid, companyname 



  FROM Sales.Customers 

  WHERE country = N'USA' 

SELECT * FROM USACusts;



As with derived tables, as soon as the outer query finishes, the CTE goes out of scope.

www.it-ebooks.info




164  

Microsoft SQL Server 2012 T-SQL Fundamentals



note

 The WITH clause is used in T-SQL for several different purposes. To avoid ambigu-

ity, when the WITH clause is used to define a CTE, the preceding statement in the same 

batch—if one exists—must be terminated with a semicolon. And oddly enough, the semi-

colon for the entire CTE is not required, though I still recommend specifying it—as I do to 

terminate all T-SQL statements.




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   212   213   214   215   216   217   218   219   ...   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