ssis expression- calculate age by using birthdate

  • I have a flat source file to import into a table. One column is birthdate, format is DT_DBDate, data is like 08/12/2010

    I want to use conditional split, if age<20, the continue, other records ignore.

    How can I use ssis to calculate the age<20 by using birthdate column.

    Thanks much

  • You might try:

    declare @dob datetime,

    @age int,

    @day datetime

    set @day = GETDATE()

    set @dob = '1932-04-18'

    set @age = datediff(yy,@dob,@day) -

    case when @day < dateadd(yy,datediff(yy,@dob,@day), @dob) then 1 else 0 end

    select @age

    Result:

    79

    If my memory serves me correctly I think the above code was written by Steve Jones, a long long time ago.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Thanks, this works in stored procedures or SQL.

    What I would like to use is in the SSIS conditional split editor, to filter out their birthdate <20 years old.

    The original oracle query is like this, how can I replace it with SQL ones.

    ROUND((months_between(SYSDATE,BIRTH_DATE))/12)<20

    Thanks

  • In the conditional split you could compare the birth date to today's date minus 20 years.

    BirthDate > DATEADD("yy",-20,@[System::StartTime])

    Just be sure to watch your boundary conditions. @[System::StartTime] is date/time and I'm guessing birth date is just days.

  • I think we can also use derived column transformation and use the datediff() function and system time

    to get the age .

Viewing 5 posts - 1 through 4 (of 4 total)

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