April 1, 2012 at 1:54 am
hi all,
i have a table like this
table1(Id,username,DateOfBirth)
i have alot of data in this table named table1
1 -Now i want to select/show only those whose age is from 3years to 5years.
2 - show those whos age is less than 1 year.
how will be a query for this?
April 1, 2012 at 6:23 am
Are you looking for something like this?
DECLARE @table1 TABLE
(
id INT IDENTITY(1,1),
DateOfBirth DATETIME
)
INSERT INTO @table1
SELECT '20060331' UNION ALL
SELECT '20060401' UNION ALL
SELECT '20060402' UNION ALL
SELECT '20090331' UNION ALL
SELECT '20090401' UNION ALL
SELECT '20090402'
DECLARE @curDate DATETIME
SET @curDate = DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
Select *
FROM @table1
WHERE DateOfBirth > DATEADD(yy,-6, @curDate)
AND DateOfBirth <= DATEADD(yy,-3, @curDate)
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply