Avatar of johnnyg123
Flag for United States of America asked on

Sql server 2000 query

I have 4 ms sql server 2000 tables with the same layout but populated with 4 different quarters of data for shops
(I know it is in the sql server 2005 zone but there was no 2000 zone)

Since shops open and close somewhat frequently,  it is possible that a shop may not exist in all the tables

Here is a sample of data

Quarter1 Table

Shopid   SalesQ1
1000       100000

Quarter2 Table

Shopid   SalesQ2
1000       200000
3000       300000

Quarter3 Table

Shopid   SalesQ3
1000       300000

Quarter4 Table

Shopid   SalesQ4
1000       400000
2000       200000

I am trying to write a query that will retrieve shop and list the data
for each quarter.  (if sales don't exist for a quarter I would like 0)

Given the sample data I would like

ShopID   SalesQ1   SalesQ2  SalesQ3   SalesQ4
1000       100000    200000    300000    400000
2000        0             0              0              200000
3000        0             300000    0              0
Microsoft SQL Server 2005

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

That works....thanks!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy