November 10, 2010 at 2:53 am
Hi, Trying
trying to do a select on a unique spellID and do a count by age group, similar to a pivot?
eg. age count
16+ 20
16-24 25
See below:
Select
Distinct NEW_Spell_ID,
Case
When DateDiff(yy,Date_of_Birth,Admission_Date) <16
then '<16'
When DateDiff(yy,Date_of_Birth,Admission_Date) < 25
then '16-24'
End as [Age_Group] , count(*)
From #temp2008_11
where CommissionerCode = 'TAM00'
group by
Case
When DateDiff(yy,Date_of_Birth,Admission_Date) <16
then '<16'
When DateDiff(yy,Date_of_Birth,Admission_Date) < 25
then '16-24'
End , NEW_Spell_ID
November 10, 2010 at 9:52 am
This looks like it should work. What kind of problem are you having.
You might want to take a look at the first article in my signature. Posting CREATE TABLE and INSERT statements with sample data that shows your problem helps us out a lot.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
November 10, 2010 at 9:54 am
What precisely is a "temp column"? A column in a temp table?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
November 11, 2010 at 2:44 am
Thanks guys, i've managed to solve it
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply