I've serched google and stackoverflow before posting this. There are many post on this case, but I can't find the problem in my query.
DECLARE @hipero_a int
SET @hipero_a = 1
SELECT
CASE @hipero_a
WHEN 1 THEN --month
(
SELECT Year(o.AccomplishDate) AS [Rok], Month(o.AccomplishDate) AS [Miesiąc], SUM(oi.Price) AS [Przychód]
FROM Orders o JOIN OrdersItems oi ON oi.OrderId = o.Id
WHERE o.State = 0
GROUP BY Year(o.AccomplishDate), Month(o.AccomplishDate)
--ORDER BY Year(o.AccomplishDate), Month(o.AccomplishDate) ASC
)
WHEN 2 THEN --year
(
SELECT Year(o.AccomplishDate) AS [Rok], SUM(oi.Price) AS [Przychód]
FROM Orders o JOIN OrdersItems oi ON oi.OrderId = o.Id
WHERE o.State = 0
GROUP BY Year(o.AccomplishDate)
--ORDER BY Year(o.AccomplishDate) ASC
)
END
I get errors:
Msg 116, Level 16, State 1, Line 14 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Msg 116, Level 16, State 1, Line 22 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
What is wrong?