Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

TSQL to add two timr stamps

$
0
0

Hi All,

Below is my query

Select   [Job Name],

(SUBSTRING(run_duration, 1, 2) + ':' + SUBSTRING(run_duration, 3, 2) + ':' +
        SUBSTRING(run_duration, 5, 2)) AS [Run_Duration(HH:MM:SS)],Convert(Date,Convert (varchar(20),run_date),103) As [Run_Date] ,

		(SUBSTRING(run_Time, 1, 2) + ':' + SUBSTRING(run_Time, 3, 2) + ':' +
        SUBSTRING(run_Time, 5, 2)) AS [Job _Started Time],
		Case when run_status=1 Then 'Completed'
		When run_status=0 then 'Failed'
		Else 'In Progress' end as [Job Status]
		 from  (		
		Select k.name as [Job Name], run_date,
		[run_duration] = ((RIGHT('000000' + CONVERT(varchar(6), run_duration), 6))),
		((RIGHT('000000' + CONVERT(varchar(6), run_Time), 6))) as
		Run_Time,run_status 
		from Msdb..sysjobhistory j inner join msdb ..sysjobs k
		on	K.job_ID=j.Job_ID
		Where run_date=CONVERT(VARCHAR(10), GETDATE(), 112)  and step_id=0 
)a
Order by  [Job Name]


The above is my query .. U will get the Results as Run_Duration and Job_Started_Time .. Here what i wanted to do is, i wanted to calculate Job_End_Time as [Run_Duration]+[Job_Started_Time]..

Can anyone rectify and update the query

Thanks 

Khushi


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>