View previous topic :: View next topic |
Author |
Message |
misi Beginner
Joined: 14 Apr 2004 Posts: 13 Topics: 10
|
Posted: Wed Feb 07, 2007 10:45 pm Post subject: default count(*) of 0 when row not found |
|
|
I want to display the count as 0 even though the select retrieves no rows .
i am running this query
Code: |
select cust_id,count(*) from cust_info where cust_amt_spent > 2000
|
if no rows found then i want to display
Code: |
cust_id count
-------- -------
000000 0
|
If we did find rows then we should not display this deault record.
Please help |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Feb 08, 2007 7:16 am Post subject: |
|
|
misi,
Try this
Code: |
SELECT CUST_ID
,COUNT(*)
FROM TABLE
WHERE CUST_AMT_SPENT > 2000
GROUP BY CUST_ID
UNION
SELECT CHAR('000000 ')
,CHAR('0)
FROM SYSIBM.SYSDUMMY1
WHERE IBMREQD = (SELECT CASE WHEN COUNT(*) = 0
THEN CHAR('Y') ELSE CHAR('N') END
FROM TABLE
WHERE CUST_AMT_SPENT > 2000)
;
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|