SQL Date Issue

  • Hi,

    I wish to create a column 'GoalBehindFlag' which will work like a flag providing me 0s and 1s if the datetime saved in another column is greate than or less than system date time.

    Can anyone please correct me where I am going wrong in this:

    select a.casecode, a.[Goal_Weighing],b.ddate, (b.ddate < sysdatetime) as GoalBehindFlag

    from [dbo].[VRep_Calc_1] as a

    inner join [dbo].[VRep_Goals] as b

    on a.casecode = b.casecode

  • Sounds like you need a case statement:

    select a.casecode, a.[Goal_Weighing],b.ddate, CASE WHEN b.ddate < GETDATE() THEN 0 ELSE 1 END as GoalBehindFlag

    from [dbo].[VRep_Calc_1] as a

    inner join [dbo].[VRep_Goals] as b

    on a.casecode = b.casecode

  • You could also use IIF such as

    select iif(a<b,1,0) as test

    There are no facts, only interpretations.
    Friedrich Nietzsche

  • barry.mcconnell (6/11/2013)


    You could also use IIF such as

    select iif(a<b,1,0) as test

    This was posted in the 2008 forum, so I'm assuming that 2012-only features aren't applicable.

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

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