The following statement converts time string (nvarchar) in mm:ss.ms format to Time
print DATEADD(ms, (ISNULL(LEFT(TRY_PARSE(RIGHT(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'),LEN(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))-CHARINDEX('.',ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))) AS INT), 2), 0)) * 10,
DATEADD(s, ISNULL(TRY_PARSE(LEFT(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'),LEN(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))-CHARINDEX('.',ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))) AS INT), 0),
DATEADD(mi, ISNULL(TRY_PARSE(LEFT(@timeString,CHARINDEX(':',@timeString)-1) AS INT), 0), '0:0')))
print DATEADD(ms, (ISNULL(LEFT(TRY_PARSE(RIGHT(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'),LEN(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))-CHARINDEX('.',ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))) AS INT), 2), 0)) * 10,
DATEADD(s, ISNULL(TRY_PARSE(LEFT(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'),LEN(ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))-CHARINDEX('.',ISNULL(LEFT(RIGHT(@timeString,LEN(@timeString)-CHARINDEX(':',@timeString)), 5), '0'))) AS INT), 0),
DATEADD(mi, ISNULL(TRY_PARSE(LEFT(@timeString,CHARINDEX(':',@timeString)-1) AS INT), 0), '0:0')))
No comments:
Post a Comment