Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
thanksfor help
Posting Yak Master
106 Posts |
Posted - 2009-04-30 : 19:03:13
|
I need query help in populating the missing products.Here is the sample product table Product ABCDXYZPQRSMMNSALES dataQuarter Product AmountQ1 ABCD 100Q1 XYZ 200Q2 PQRS 100Q2 ABCD 300I need query to generate the sales data with zero for the missing productsQuarter Product AmountQ1 ABCD 100Q1 XYZ 200Q1 PQRS 0Q1 MMN 0Q2 PQRS 100Q2 ABCD 300Q2 XYZ 0Q2 MMN 0Any help is very much appreciated.Thanks |
|
singularity
Posting Yak Master
153 Posts |
Posted - 2009-04-30 : 19:25:16
|
[code]select a.quarter, a.product, isnull(b.amount,0) as amountfrom (select distinct p.product, s.quarter from product_data p cross join sales_data s) aleft join sales_data b on a.product = b.product and a.quarter = b.quarter[/code] |
|
|
|
|
|