question

dhungs avatar image
dhungs asked

How to compare HH:MM stored as varchar with HH:MM?

Hi: I have time difference between two dates stored as HH:MM (varchar) in a column(TAT) now I need to update the other column(SLA) as Pass if TAT is <=120 Hrs else Fail. I tried using where clause as in the following syntax: update SLA as 'Pass' where TAT <= '120:00' update SLA as 'Fail' where TAT > '120:00' but this syntax is taking only 12:00 instead of 120:00 please suggest.
sql server 2008 r2
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
KenJ avatar image
KenJ answered
You've gotten into the spot where you are comparing character strings when you want to be comparing duration as a numeric. To compare the duration with 120 hours 0 minutes, you'll have to convert the string values into numbers. For example, this query would miss a 13 hour 0 minute duration: select * from #test where TAT
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.