Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

SQL Server view

Not sure if this is "so-able."

I have three tables with sales information in them.

Each table has a "cust_no" field, year, sales.

How do I write a view that has
Customer          TY Sales      SalesYR-1   SalesYR-2
1                          200               100                  0
2                             0                   200              0
Avatar of gnar
gnar
Flag of United States of America image

What about just joining the tables on that cust_no field?

Something like:




SELECT a.cust_no, a.sales, b.sales, c.sales
FROM tablea a
JOIN tableb b on a.cust_no = b.cust_no
JOIN tablec c on b.cust_no = c.cust_no

Open in new window

Avatar of Larry Brister

ASKER

gnar:
The cust_no doesn't exist in all tables.  I need have a column that has all the cust_no's whatever table they're in and then place a zero dollars in the sales part where they don't exist.
ASKER CERTIFIED SOLUTION
Avatar of ee_rlee
ee_rlee
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
WOW!  Excellent script.  Thanks and I'm on my way!