CONVERT AND TIMES AFTER MIDNIGHT

  • To simplify. I want the statement to equal 1 when the following criteria is met:

    Walktime = 2012-04-01 20:00:00:000 MINUS Validated AppointmentContactEnded = 2012-04-02 02:00:00:000

    is greater than 4 hours. In this case it would be 6 hours so would have the value of 1.

    Hi

    I have the following SQL statement:

    case when (convert(varchar(5),[Validated AppointmentContactEnded]-WalkinTime,108) > '04:00')

    then 1 end as 'TEST',

    It works ok with the exception of when the [Validated AppointmentContactEnded] time is after midnight on the next day e.g.

    ValAppConEnd = 01:30 minus WalkinTime = 20:00

    This should give a value of 1 but it doesn't.

    The time values before they are converted are stored as

    yyyy-mm-dd hh:mm:ss:sss

    Is there a way around this?

  • Not sure if I understand your requirement correctly but I think this should work:

    SELECT

    CASE WHEN DATEDIFF(hh,[WalkinTime],[Validated AppointmentContactEnded]) < 4

    THEN 1

    ELSE 0

    END

    [font="Verdana"]Markus Bohse[/font]

  • Thanks Markus

    Works perfectly.

    Kind regards

    Malcolm

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

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