MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

default count(*) of 0 when row not found

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
misi
Beginner


Joined: 14 Apr 2004
Posts: 13
Topics: 10

PostPosted: Wed Feb 07, 2007 10:45 pm    Post subject: default count(*) of 0 when row not found Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Feb 08, 2007 7:16 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group