I have this code that I use in SQL for Vb.net values for a specific Department, but now I need all the departments to be shown.
SELECT SUM(Price) AS 'Total'
,CONVERT(char(7), date, 120) AS 'year'
,Department as 'Department'
FROM [dbo].[Expenses]
WHERE Department=('Electronics')
GROUP BY Rollup (CONVERT(char(7), date, 120)), Department
HAVING CONVERT(char(7), date, 120) >= '2017-01'
AND CONVERT(char(7), date, 120) <= '2020-01'
I could use the Union to show me the other Departments like here:
SELECT SUM(Price) AS 'Total'
,CONVERT(char(7), date, 120) AS 'year'
,Department as 'Department'
FROM [dbo].[Expenses]
WHERE Department=('Electronics')
GROUP BY Rollup (CONVERT(char(7), date, 120)), Department
HAVING CONVERT(char(7), date, 120) >= '2017-01'
AND CONVERT(char(7), date, 120) <= '2020-01'
Union
SELECT SUM(Price) AS 'Total'
,CONVERT(char(7), date, 120) AS 'year'
,Department as 'Grocery'
FROM [dbo].[Expenses]
WHERE Department=( 'Grocery')
GROUP BY Rollup (CONVERT(char(7), date, 120)), Department
HAVING CONVERT(char(7), date, 120) >= '2017-01'
AND CONVERT(char(7), date, 120) <= '2020-01'
But like this i could not use it for my Charts in Vb.net.
Is it possible to do it differently?
What I have tried:
This is what I have tried, it doesn't give me any error but also it won't give me any data
SELECT SUM(Price) AS 'Total'
,CONVERT(char(7), date, 120) AS 'year'
,Department as 'Department'
FROM [dbo].[Expenses]
WHERE Department=('Electronics,Grocery')
GROUP BY Rollup (CONVERT(char(7), date, 120)), Department
HAVING CONVERT(char(7), date, 120) >= '2017-01'
AND CONVERT(char(7), date, 120) <= '2020-01'
But I have no results.
Thank you for your help.