Groups | Blog | Home
all groups > sql server new users > october 2005 >

sql server new users : SQL Question: Views Help


limsy NO[at]SPAM newsgroups.nospam
10/4/2005 12:00:00 AM
Hi ppl,

I need to create a view which contains both SALES and CANCELLATION/RETURN
data.
Is it possible for a VIEW to store data from 2 sources?

Eg.

Create VIEW MyView (RefNo, Date, Data1, Data2, etc...)
As Select (sales_table.SalesNo, sales_table.SalesDate, ..)
From sales_table
Where ....

How to I add data from my table containing cancellations and returns? Add
more AS SELECT statements at the bottom?
If this is not the way... plz point me to the right method.

The idea is to be able to retrieve just SALES ... or just RETURNS ... or
BOTH (sales having +ve while returns -ve)
from 1 View.

Any info/help is greatly appreciated. Thanks.

Limsy.


SQL
10/4/2005 5:12:43 AM
Create VIEW MyView (RefNo, Date, Data1, Data2, etc...)
As Select (sales_table.SalesNo, sales_table.SalesDate, ..)
[quoted text, click to view]
Where ....
union all
Select (sales_table.SalesNo, sales_table.SalesDate, ..)
[quoted text, click to view]
Where ....


http://sqlservercode.blogspot.com/
Tom Moreau
10/4/2005 8:14:59 AM
Please post the DDL for the underlying tables, plus INSERT statements of
sample data and the expected output.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
[quoted text, click to view]
Hi ppl,

I need to create a view which contains both SALES and CANCELLATION/RETURN
data.
Is it possible for a VIEW to store data from 2 sources?

Eg.

Create VIEW MyView (RefNo, Date, Data1, Data2, etc...)
As Select (sales_table.SalesNo, sales_table.SalesDate, ..)
From sales_table
Where ....

How to I add data from my table containing cancellations and returns? Add
more AS SELECT statements at the bottom?
If this is not the way... plz point me to the right method.

The idea is to be able to retrieve just SALES ... or just RETURNS ... or
BOTH (sales having +ve while returns -ve)
from 1 View.

Any info/help is greatly appreciated. Thanks.

Limsy.


AddThis Social Bookmark Button