Selecting records issue

  • 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?

  • 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)



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply