Inline view as a column : Inline view « View « SQL Server / T-SQL

SQL Server / T-SQL
1. Aggregate Functions
2. Analytical Functions
3. Constraints
4. Cursor
5. Data Set
6. Data Type
7. Database
8. Date Timezone
9. Index
10. Insert Delete Update
11. Math Functions
12. Select Query
13. Sequence
14. Store Procedure Function
15. String Functions
16. Subquery
17. System
18. Table
19. Table Joins
20. Transact SQL
21. Transaction
22. Trigger
23. View
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL » View » Inline view 
Inline view as a column

2CREATE TABLE Customers 
3>      CustomerID nchar (5NOT NULL ,
4>      CompanyName nvarchar (40NOT NULL ,
5>      ContactName nvarchar (30NULL ,
6>      ContactTitle nvarchar (30NULL ,
7>      Address nvarchar (60NULL ,
8>      City nvarchar (15NULL ,
9>      Region nvarchar (15NULL ,
10>     PostalCode nvarchar (10NULL ,
11>     Country nvarchar (15NULL ,
12>     Phone nvarchar (24NULL ,
13>     Fax nvarchar (24NULL
14)
15> GO
1>
2INSERT Customers VALUES('1','A','Maria',    'Sales',  'Str. 57', 'Berlin'    ,NULL,'12209', 'Germany','111-1111111','111-1111111')
3INSERT Customers VALUES('2','M','Joe',      'Owner',  'Ave. 231','Vancouver' ,NULL,'05023', 'Mexico', '(222222-3332',NULL)
4INSERT Customers VALUES('3','H','Thomas',   'Sales',  'Sq.  111','London'    ,NULL,'1D00P', 'UK',     '(444444-4444','(444444-4444')
5INSERT Customers VALUES('4','B','Berg',     'Order',  'Blv    8','Toronto'   ,NULL,'00222', 'Sweden', '4444-55 55 65','5555-55 55 55')
6INSERT Customers VALUES('5','S','Moos',     'Sales',  'Fort  57','New York'  ,NULL,'68306', 'Germany','6666-66666','6666-77777')
7INSERT Customers VALUES('6','F','Cite',     'Manager','24      ','Dalles'    ,NULL,'67000', 'France', '88.60.15.31','88.60.15.32')
8INSERT Customers VALUES('7','C','Sommer',   'Owner',  'Araq, 67','Paris'     ,NULL,'28023', 'Spain',  '(91555 22 82','(91555 91 99')
9INSERT Customers VALUES('8','P','Leb',      'Owner',  '12      ','Beijing'   ,NULL,'13008', 'France', '91.24.45.40','91.24.45.41')
10INSERT Customers VALUES('9','D','Elizabeth','Manager','23 Blvd.','Tsawassen','BC', 'T2F8M4','Canada', '(604555-4729','(604555-3745')
11> go

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)
1CREATE TABLE Orders (
2>      OrderID int NOT NULL ,
3>      CustomerID nchar (5NULL ,
4>      EmployeeID int NULL ,
5>      OrderDate datetime NULL ,
6>      RequiredDate datetime NULL ,
7>      ShippedDate datetime NULL ,
8>      ShipVia int NULL ,
9>      Freight money NULL DEFAULT (0),
10>     ShipName nvarchar (40NULL ,
11>     ShipAddress nvarchar (60NULL ,
12>     ShipCity nvarchar (15NULL ,
13>     ShipRegion nvarchar (15NULL ,
14>     ShipPostalCode nvarchar (10NULL ,
15>     ShipCountry nvarchar (15NULL
16)
17> GO
1>
2>    SELECT cu.CompanyName,
3>       (SELECT Min(OrderDate)
4>               FROM Orders o
5>               WHERE o.CustomerID = cu.CustomerID)
6>               AS "Order Date"
7>    FROM Customers cu
8> GO
CompanyName                              Order Date
---------------------------------------- -----------------------
A                                                           NULL
M                                                           NULL
H                                                           NULL
B                                                           NULL
S                                                           NULL
F                                                           NULL
C                                                           NULL
P                                                           NULL
D                                                           NULL

(rows affected)
1>
2> drop table Orders;
3> drop table Customers;
4> GO

 
Related examples in the same category
1. Using Derived Tables
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.