select STUFF(
STUFF(RIGHT('000000' + CAST([run_duration] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
AS [LastRunDuration (HH:MM:SS)]
from sysjobhistory
The query I have given above works fine but I am trying to understand it more clear. My observations are:
- First we cast the run duration into
varcharand with a length 6 and append six 0's to right of it which becomes if its is10then00000010 - After we use the stuff function to insert
:in between this here it is at the 3rd position so the above one becomes00:000010 - Again we use stuff to insert the
:symbol to the sixth position so it becomes00:00:0010
But when I run the query if there is a values 10 it shows as 00:00:10.
How that can be?
