Hi All
I need to display the count of no of jobs running in SAP BODS repository table , starting at the Start_time and End_time of the jobs present in the table.
The table structure consists of :
The Expected output should be in the format:-
RunID | JobName | Start_time | End_Time | JobsCount at StartTime | JobsCount at EndTime |
Following was the query tried on Sql-Server-2012:-
declare @count int=1,
@max int,
@stime datetime,
@endtime datetime,
@runid int,
@jobname varchar(1000)
with cte as(
select distinct RUN_ID,JOB_NAME,START_TIME,END_TIME,EXECUTION_TIME from COMP_HIS_TBL(nolock)
where STATUS='Failure'
);
,temp_tab as(
select ROW_NUMBER() over(order by run_id)row_number,* from cte)
select * into #temp from temp_tab
order by 1,EXECUTION_TIME desc
select @max=MAX(ROW_NUMBER) from #temp
while (@count<=@max)
begin
select @stime=start_time,@endtime=end_time,@runid=run_id,@jobname=job_name from #temp where
ROW_NUMBER=@count
select
@runid RUN_ID ,@jobname JOB_NAME,@starttime Start_time ,@endtime end_time
select count(RUN_ID) as JOBS_AT_START_TIME from COMP_HIS_TBL(nolock)
where @stime between START_TIME and END_TIME
select count(RUN_ID) as JOBS_AT_END_TIME from COMP_HIS_TBL(nolock)
where @endtime between START_TIME and END_TIME
set @count=@count+1
end
--DROP TABLE #TEMP
Which is working fine for few jobs, but ending up with the warning "Query completed with errors!! and ending up with hardly "1 row retrieved". Please provide any alternative solution to this. The same requirement is not possible by other ways like Joins and others??