|
 |
sql_language thread: Quarterly reports...
Message #1 by "Arbon Reimer" <arbon_reimer@h...> on Fri, 15 Nov 2002 16:13:59
|
|
It turns out to be a real simple fix. The case statement in the group by
has to EXACTLY match the case statement in the select portion when I typed
it in I accidentally did "fourth" in one and "Fourth" in the other. Copy
the first select and then paste it in the group by and then it should work.
(I tested it on my and when I did that it then worked again. Sorry for the
confusion.
Brian
-----Original Message-----
From: Arbon Reimer [mailto:arbon_reimer@h...]
Sent: Thursday, November 21, 2002 10:17 AM
To: sql language
Subject: [sql_language] RE: Quarterly reports...
Looks great... only that I'm getting an error that TSPP.Date_To is invalid
because it's not contained in the GROUP BY Clause...
I modified the GROUP BY to only GROUP BY TSPP.Date_TO but that didn't
appear to get the results quite right...
Do you perhaps have any suggestions for modifying it slightly to make it
work properly? It's the closest thing I've seen. I've not used select
case in SQL before! Thank you very much for your help.
-AR
===========================================
select
case
when MONTH(TSPP.Date_To) between 1 AND 3 then 'First Quarter'
when MONTH(TSPP.Date_To) between 4 and 6 then 'Second Quarter'
when MONTH(TSPP.Date_To) between 7 and 9 then 'Third Quarter'
when MONTH(TSPP.Date_To) between 10 and 12 then 'Fourth Quarter'
end as 'TaxQuarter',
ISNULL(SUM(FUTA_Withholding),0) as TotalTax
FROM Payroll_Master
JOIN
Timesheet.dbo.Pay_Period TSPP ON
Payroll_Master.Pay_Period_Number = TSPP.Period
WHERE
TSPP.[Year] = YEAR(GETDATE())
group by
case
when MONTH(TSPP.Date_To) between 1 AND 3 then 'First Quarter'
when MONTH(TSPP.Date_To) between 4 and 6 then 'Second Quarter'
when MONTH(TSPP.Date_To) between 7 and 9 then 'Third Quarter'
when MONTH(TSPP.Date_To) between 10 and 12 then 'fourth Quarter'
end
order by taxQuarter
This will get them in alphabetical to get them in chronological you can use
"Quarter 1", "Quarter 2" etc. or a separate order column that has the
numeric quarter.
Good luck.
Brian Freeman
|
|
 |