Create the view that combines all sales tables with union : Filter view « View « 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 » View » Filter view 
16. 6. 4. Create the view that combines all sales tables with union
3CREATE TABLE Sales_West (
4>     Ordernum INT,
5>     total money,
6>     region char(5check (region = 'West'),
7>     primary key (Ordernum, region)
8>     )
9CREATE TABLE Sales_North (
10>     Ordernum INT,
11>     total money,
12>     region char(5check (region = 'North'),
13>     primary key (Ordernum, region)
14>     )
15CREATE TABLE Sales_East (
16>     Ordernum INT,
17>     total money,
18>     region char(5check (region = 'East'),
19>     primary key (Ordernum, region)
20>     )
21CREATE TABLE Sales_South (
22>     Ordernum INT,
23>     total money,
24>     region char(5check (region = 'South'),
25>     primary key (Ordernum, region)
26>     )
27> GO
1>
2INSERT Sales_West VALUES (165442465'West')
3INSERT Sales_West VALUES (321234309'West')
4INSERT Sales_North VALUES (165443229'North')
5INSERT Sales_North VALUES (265444000'North')
6INSERT Sales_East VALUES 2222243332'East')
7>
8INSERT Sales_East VALUES 7777710301'East')
9INSERT Sales_South VALUES (234564320'South')
10INSERT Sales_South VALUES (165449999'South')
11> GO

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)

(rows affected)
1>
2> -- Create the view that combines all sales tables
3CREATE VIEW Sales_National
4> AS
5SELECT *
6FROM Sales_West
7>     UNION ALL
8SELECT *
9FROM Sales_North
10>     UNION ALL
11SELECT *
12FROM Sales_East
13>     UNION ALL
14SELECT *
15FROM Sales_South
16> GO
1>
2>
3SELECT *
4FROM Sales_National
5WHERE region = 'South'
6> GO
Ordernum    total                 region
----------- --------------------- ------
      16544             9999.0000 South
      23456             4320.0000 South

(rows affected)
1>
2>
3> drop TABLE Sales_West
4> drop TABLE Sales_North
5> drop TABLE Sales_East
6> drop TABLE Sales_South
7> GO
1>
2> drop VIEW Sales_National;
3> GO
16. 6. Filter view
16. 6. 1. A script that creates a stored procedure as a filter-view
16. 6. 2. A SELECT statement that uses the BankersMin view with where clause
16. 6. 3. Use view to join four tables
16. 6. 4. Create the view that combines all sales tables with union
16. 6. 5. Create a view with outer join and full join
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.