Nested IFs within DATEDIFF

Last post 09-09-2008 12:34 PM by jpruneda. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 09-08-2008 8:23 AM

    Nested IFs within DATEDIFF

    I need to do a DateDiff to get the number of days between NOW and conditionally a date field based on a status flag. There are about seven different statuses and and about the same number of different date fields that I would need to go after.

    Should I use nested IFs inside my DateDiff expression or use IFs to conditionally bring the right date back into a query column and then do my DateDiff against the new column?

    If I should use a nested IF inside my DATEDIFF what would that syntax look like?


    Thanks!

    Frank
  • 09-09-2008 12:34 PM In reply to

    Re: Nested IFs within DATEDIFF

    Either method should work. You should also look at the user defined function syntax as a possible solution.  Please consult the documentation on 3 different methods.

     

    Jose

     

    drop table h1

    create table h1 ( status int , c2 date )

    insert into h1  values ( 1, '2000-12-12' )

    insert into h1 values  ( 2, '2002-01-01' )

     

    select datediff ( day,  if ( status = 1,  now() , c2 ), now() ) from h1

     

Page 1 of 1 (2 items)