With as : With « Transact SQL « SQL Server / T-SQL Tutorial

SQL Server / T-SQL Tutorial
1. Query
2. Insert Delete Update
3. Table
4. Table Join
5. Data Types
6. Set Operations
7. Constraints
8. Subquery
9. Aggregate Functions
10. Date Functions
11. Math Functions
12. String Functions
13. Data Convert Functions
14. Analytical Functions
15. Sequence Indentity
16. View
17. Index
18. Cursor
19. Database
20. Transact SQL
21. Procedure Function
22. Trigger
23. Transaction
24. XML
25. System Functions
26. System Settings
27. System Tables Views
28. User Role
29. CLR
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL Tutorial » Transact SQL » With 
20. 25. 4. With as
20CREATE TABLE Employees (
21>     EmployeeID int IDENTITY (11NOT NULL ,
22>     LastName nvarchar (20NOT NULL ,
23>     FirstName nvarchar (10NOT NULL ,
24>     Title nvarchar (30NULL ,
25>     TitleOfCourtesy nvarchar (25NULL ,
26>     BirthDate datetime NULL ,
27>     HireDate datetime NULL ,
28>     Address nvarchar (60NULL ,
29>     City nvarchar (15NULL ,
30>     Region nvarchar (15NULL ,
31>     PostalCode nvarchar (10NULL ,
32>     Country nvarchar (15NULL ,
33>     HomePhone nvarchar (24NULL ,
34>     Extension nvarchar (4NULL ,
35>     Photo image NULL ,
36>     Notes ntext NULL ,
37>     ReportsTo int NULL ,
38>     PhotoPath nvarchar (255NULL
39>
40)
41> GO

1>
2>
3>
4> WITH Args1 AS
5(
6>   SELECT LastName, FirstName, BirthDate,
7>     DATEDIFF(year, BirthDate, GETDATE()) AS Diff,
8>     CAST(CONVERT(CHAR(8), GETDATE()112AS DATETIMEAS Today
9>   FROM dbo.Employees
10),
11>
12> Args2 AS
13(
14>   SELECT LastName, FirstName, BirthDate, Today,
15>     DATEADD(year, Diff, BirthDateAS BDCur,
16>     DATEADD(year, Diff + 1, BirthDateAS BDNxt
17>   FROM Args1
18),
19> Args3 AS
20(
21>   SELECT LastName, FirstName, BirthDate, Today,
22>     BDCur + CASE WHEN DAY(BirthDate29 AND DAY(BDCur28
23>       THEN ELSE END AS BDCur,
24>     BDNxt + CASE WHEN DAY(BirthDate29 AND DAY(BDNxt28
25>       THEN ELSE END AS BDNxt
26>   FROM Args2
27)
28>
29SELECT LastName, FirstName, BirthDate,
30>   CASE WHEN BDCur >= Today THEN BDCur ELSE BDNxt END AS BirthDay
31FROM Args3;
32>
33> drop table Employees;
34> GO
LastName             FirstName  BirthDate               BirthDay
-------------------- ---------- ----------------------- -----------------------
Today                Mary       2008-08-17 00:00:00.000 2008-08-17 00:00:00.000
1>
20. 25. With
20. 25. 1. Common Table Expressions
20. 25. 2. Select from Common Table Expressions
20. 25. 3. Syntax for a CTE for recursive queries is
20. 25. 4. With as
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.