Помогает ли это указать вам правильное направление?
Я использую Общие табличные выражения ниже, чтобы подвести некоторые данные.
Эта версия может работать довольно страннозначения «time» в диапазоне от «24:00:00», а также значения «time» без начального нуля (например, «7:00:00»).
WITH s1
as
(
SELECT '31:50:12' as SHIFTSTART
,CAST(LEFT('31:50:12', CHARINDEX(':','31:50:12') - 1) as int) as my_hours_parsed
,SUBSTRING('31:50:12', CHARINDEX(':','31:50:12'), 10) as my_min_sec
UNION
SELECT '21:15:23' as SHIFTSTART
,CAST(LEFT('21:15:23', CHARINDEX(':','21:15:23') - 1) as int) as my_hours_parsed
,SUBSTRING('21:15:23', CHARINDEX(':','21:15:23'), 10) as my_min_sec
UNION
SELECT '7:00:00' as SHIFTSTART
,CAST(LEFT('7:00:00', CHARINDEX(':','7:00:00') - 1) as int) as my_hours_parsed
,SUBSTRING('7:00:00', CHARINDEX(':','7:00:00'), 10) as my_min_sec
UNION
SELECT '49:00:00' as SHIFTSTART
,CAST(LEFT('49:00:00', CHARINDEX(':','49:00:00') - 1) as int) as my_hours_parsed
,SUBSTRING('49:00:00', CHARINDEX(':','49:00:00'), 10) as my_min_sec
UNION
SELECT '99:23:00' as SHIFTSTART
,CAST(LEFT('99:23:00', CHARINDEX(':','99:23:00') - 1) as int) as my_hours_parsed
,SUBSTRING('99:23:00', CHARINDEX(':','99:23:00'), 10) as my_min_sec
UNION
SELECT '157:23:00' as SHIFTSTART
,CAST(LEFT('157:23:00', CHARINDEX(':','157:23:00') - 1) as int) as my_hours_parsed
,SUBSTRING('157:23:00', CHARINDEX(':','157:23:00'), 10) as my_min_sec
)
SELECT s1.SHIFTSTART
,s1.my_hours_parsed
,s1.my_min_sec
,CASE WHEN s1.my_hours_parsed > 24
THEN 'Houston, we have a problem'
ELSE 'Works for me'
END as SHIFTSTART_profile
,CAST(s1.my_hours_parsed - 24*(s1.my_hours_parsed/24) AS varchar(2)) + s1.my_min_sec as my_time_mod
FROM s1;
Эторезультат ...
SHIFTSTART my_hours_parsed my_min_sec SHIFTSTART_profile my_time_mod
1 157:23:00 157 :23:00 Houston, we have a problem 13:23:00
2 21:15:23 21 :15:23 Works for me 21:15:23
3 31:50:12 31 :50:12 Houston, we have a problem 7:50:12
4 49:00:00 49 :00:00 Houston, we have a problem 1:00:00
5 7:00:00 7 :00:00 Works for me 7:00:00
6 99:23:00 99 :23:00 Houston, we have a problem 3:23:00
Надеюсь, это поможет