I really hope someone can help me with this sql query, been racking my brain but I know it's possible...This is my current query and produces the right format:
DECLARE
@Price1 NVARCHAR(20),
@Price2 NVARCHAR(20),
@Price3 NVARCHAR(20),
@Price4 NVARCHAR(20)
SET @Price1 = (select Price from CakeSize where SizeId = '1')
SET @Price2 = (select Price from CakeSize where SizeId = '2')
SET @Price3 = (select Price from CakeSize where SizeId = '3')
SET @Price4 = (select Price from CakeSize where SizeId = '4')
SELECT
c.Name_en as Flavor,
@Price1 as Price1,
@Price2 as Price2,
@Price3 as Price3,
@Price4 as Price4
FROM
cake a
Left outer JOIN CakeSize b ON a.SizeId = b.SizeId
Left outer JOIN CakeFlavor c ON a.FlavorId = c.FlavorId
Left outer JOIN CakeFilling d ON a.FillingId = d.FillingId
Left outer JOIN CakeIcing f ON a.IcingId = f.IcingId
group by c.Name_en
I can't seem to get the sum of all the prices from all the tables and display.
I am able to retrieve the data but can't format it like above?
SELECT
c.Name_en as Flavor,
ISNULL(b.Price, 0) + ISNULL(c.Price, 0) + ISNULL(d.Price, 0) + ISNULL(f.Price, 0) as aPrice,
ISNULL(b.Price, 0) + ISNULL(c.Price, 0) + ISNULL(d.Price, 0) + ISNULL(f.Price, 0) as bPrice,
ISNULL(b.Price, 0) + ISNULL(c.Price, 0) + ISNULL(d.Price, 0) + ISNULL(f.Price, 0) as cPrice,
ISNULL(b.Price, 0) + ISNULL(c.Price, 0) + ISNULL(d.Price, 0) + ISNULL(f.Price, 0) as dPrice
FROM
cake a
Left Outer JOIN CakeSize b
ON a.SizeId = b.SizeId
Left Outer JOIN CakeFlavor c
ON a.FlavorId = c.FlavorId
Left Outer JOIN CakeFilling d
ON a.FillingId = d.FillingId
Left Outer JOIN CakeIcing f
ON a.IcingId = f.IcingId
Instead of 4 rows for chocolate cake, I would like to have the output above; 1 row for chocolate cake. (Carrot cake is $5 less than the rest)
CORRECT DATA, WRONG FORMAT
Column aPrice rows 1,2,3,4 contain the correct values for chocolate cake.
(wanting the below format for each flavor)
Chocolate 18.95 18.95 23.50 38.50