SQL Question (DB2 or straight)

Status
Not open for further replies.

reboot

Ars Legatus Legionis
10,818
ok.. this is an easy one but I can't figure it out... maybe I need more coffee..

This is on DB2 7.1

I have a table called staging.tracking.
Certain jobs write their name to it and a number.

What I want is :
if jobs ran, list their name and corresponding number
if no jobs ran write 'NO JOBS' (or just zero if you will, I can trap it)

I figured this would work, but it doesn't

select count(*), jobname, jobcount
from staging.tracking
group by jobname, jobcount ;

However, it returns nothing. (not zero, nothing)

It works without jobname and jobcount (i.e. it returns zero)

How can I do this ??
 

reboot

Ars Legatus Legionis
10,818
no answer yet ? You guys are usually all over these questions ;)

Let me clarify :

This tells me if the job ran :

Code:
select CASE count(*) WHEN 0 THEN 'myjob didn''t run in the last 24h' ELSE 'myjob ran succesfully in the last 24h' END as MYJOB_SUCCESS
from staging.tracking
where  jobname = 'myjob' and start_ts > current timestamp - 24 hours ;

This tells the 'jobcount' that was written , provided the job ran :

Code:
select jobcount as JOB_ROWS
from staging.tracking
where jobname = 'myjob' and start_ts > current timestamp - 24 hours 
order by start_ts desc 
fetch first 1 rows only
;

So, if the job ran, I see 'myjob ran succesfully in the last 24h' and, for example, 15000
If it didn't , I see 'myjob didn't run in the last 24h' and nothing.

I wish to combine these two queries.
having just nothing is not an option.
 

reboot

Ars Legatus Legionis
10,818
I'm disapointed guys.. the answer was a scalar fullselect..

Code:
select CASE count(*) WHEN 0 THEN 'myjob didn''t run in the last 24h' ELSE 'myjob ran succesfully in the last 24h' END as MYJOB_SUCCESS ,
(select sum(jobcount) as JOB_ROWS
from staging.tracking
where jobname = 'myjob' and start_ts > current timestamp - 24 hours 
) as jobcount
from staging.tracking
where  jobname = 'myjob' and start_ts > current timestamp - 24 hours ;

which returns either

Code:
MYJOB_SUCCESS                       jobcount
----------------------------------- ------------------- 
myjob didn't run in the last 24h    null              

or

MYJOB_SUCCESS                       jobcount
----------------------------------- ------------------- 
myjob ran succesfully in the last   51240

[This message was edited by reboot on April 03, 2002 at 15:53.]
 
Status
Not open for further replies.