etirem (5/6/2013)
But I have different scenarios to get the persons retrieved based on the parameters for BEGIN AGE and END AGE in WHERE Clause:Like :
SELECT person, dob,
case when DATEDIFF(MONTH,dob,@SDate)/12>0 then convert(varchar,DATEDIFF(YEAR,dob,@SDate))+ ' Years' else convert(varchar,DATEDIFF(MONTH,dob,@SDate)) + ' Months' end as age
FROM @people
where --DATEDIFF(MONTH,dob,@SDate)>=1 and DATEDIFF(YEAR,dob,@SDate)<=7
--Age BETWEEN @BEGINAge AND @ENDAge
Query1: Age BETWEEN 1 Months AND 1 Years
Query2: Age BETWEEN 4 Months AND 13 Years
Query3: Age BETWEEN 1 Years AND 23 Years
Is this the last change in your requirements?
Also, looking above it looks like this even changes your last change for 4 months to 12 years.