DECLARE @Year INT = 2005, @Month INT = 7
SELECT --SequenceNo = ROW_NUMBER() OVER(ORDER BY OrderDate),
Year = Year(convert(int,OrderDate,111)),
case Month(convert(int,OrderDate,111))
when 1 then 'Janeiro'
when 2 then 'Fevereiro'
when 3 then 'Março'
when 4 then 'Abril'
when 5 then 'Maio'
when 6 then 'Junho'
when 7 then 'Julho'
when 8 then 'Agosto'
when 9 then 'Setembro'
when 10 then 'Outubro'
when 11 then 'Novembro'
when 12 then 'Dezembro'
else 'unknown'
end as "Month1",
Month = Month(convert(int,OrderDate,111)),
TotalDue = convert(money,TotalDue,1),
[Running Total] = convert(money,
(SELECT sum(convert(money,TotalDue,1))
FROM Sales.SalesOrderHeader as Header
WHERE SalesOrderID <= soh.SalesOrderID
AND year(OrderDate) = @Year
AND month(OrderDate) = @Month),
1)
FROM Sales.SalesOrderHeader soh
WHERE year(OrderDate) = @Year
AND month(OrderDate) = @Month
group by Year, Month
order by 1, 2
When I try to run group by it appears:
Error Msg 207, Level 16, State 1, Line 31 Invalid column name 'Year'. Msg 207, Level 16, State 1, Line 31 Invalid column name 'Month'.