I need my code to add the varchar CPUTM
field + varchar CPUZIPTIM
field which both has time values to see if greater than 2 hours. How do I do this when both fields are varchar. The value in CPUTM
field is '335:55:20.97'
duration time. My code is below.
CPUTM = 335:55:20.97 duration time
CPUZIPTM = 0:00:01.96 duration time
select * FROM [SMF_DATA].[dbo].[System_Management_Facility]
WHERE ((convert(varchar(13), CONVERT(time, CPUTM) + CONVERT(time, CPUZIPTM)))
> '02:00:00.00')
Using SQL server 2012 Enterprise Edition.
Best Answer
Assuming the format in the 2 columns is
hours:mm:ss[.fff]
wherehours
can be even more than 24, I think this would work:The
CROSS APPLY
are not really needed, they are there so the logic is split in parts and so you don't have a huge complicated final condition.If you wanted a different check (say 10 minutes instead of 2 hours), it would need only this change: