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 

Handling zero selected rows in query itself - for Inner quer

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


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Tue Jul 21, 2009 1:48 pm    Post subject: Handling zero selected rows in query itself - for Inner quer Reply with quote

Hi,

I have to write an inner subquery. Its supposed to be small and requirements too are minimal. However, I tried a lot framing the query as well as find it here but in vain. Please help me.

table tab1 has one column Col1 of one character byte. This table may be empty at times or have duplicates values.

e.g. it may have four rows like
Col1:
B
B
A
C

or at times may be empty also.

Requirement is: to get the distinct values and if the table is empty to get the default value 'A'. Now this has to be done within the query itself. As I said in my subject that this is going to be my subquery and I have to join these output values with some other table, so I have to do it within query itself.

thanks for your time.
_________________
Thanks.
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: Tue Jul 21, 2009 2:28 pm    Post subject: Reply with quote

seekaysk,

Untested SQL but should work based of this topic

http://www.mvsforums.com/helpboards/viewtopic.php?t=7854&highlight=count


Code:

SELECT DISTINCT COL1                                           
  FROM TABLE                                               
 UNION                                                         
SELECT CHAR('A')                                               
  FROM SYSIBM.SYSDUMMY1                                         
 WHERE IBMREQD = (SELECT CASE WHEN COUNT(*) = 0                 
                              THEN CHAR('Y') ELSE CHAR('N') END
                    FROM TABLE)

;


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Wed Jul 22, 2009 8:29 am    Post subject: Reply with quote

This is great. thanks a lot kolusu. I am learning IBMREQD parameter for the first time here. thank you so much for the prompt reply.

P.S. I was taking time to test with various scenarios and hence a delayed reply.
_________________
Thanks.
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: Wed Jul 22, 2009 10:43 am    Post subject: Reply with quote

seekaysk,

So did it work? Here is the explanation of Sysibm.sysdummy1 table

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQJ12/F.27?

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
seekaysk
Beginner


Joined: 31 Aug 2007
Posts: 49
Topics: 15

PostPosted: Wed Jul 22, 2009 3:00 pm    Post subject: Reply with quote

great. thanks again for the extended help. This is a very handy doc.
_________________
Thanks.
Back to top
View user's profile Send private message
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