Avatar of Tom Wallace
Tom Wallace
Flag for United States of America

asked on 

adding products to query with a 0 value

I have a table called_customer sales from dbo.sales. Lets say there are 3 different products in this table: candy, soda, and popcorn. the data looks like this: 


customer_ID   Product   Sales  Customer_Name

1                     candy         100      Regal

1                     soda            200     Regal

1                     popcorn      200     Regal

2                     candy          50       Cina

2                     soda            100     Cina 

3                     candy          150     Cina

4                     candy           230     FM

4                     soda             200     FM

4                     popcorn       150     FM


I need to add a placeholder for each customer that doesn't have sales for each of the product categories. For example I would want the result to look like this:


customer_ID   Product   Sales  Customer_Name
1                     candy         100      Regal
1                     soda            200     Regal
1                     popcorn      200     Regal
2                     candy          50       Cina
2                     soda            100     Cina 

2                     popcorn      0       Cina 
3                     candy          150     Cina

3                     soda              0     Cina

3                     popcorn       0      Cina
4                     candy           230     FM
4                     soda             200     FM
4                     popcorn       150     FM


How can I achieve this? Thank you for the help



Microsoft SQL Server

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon