View previous topic :: View next topic |
Author |
Message |
seekaysk Beginner
Joined: 31 Aug 2007 Posts: 49 Topics: 15
|
Posted: Tue Jul 21, 2009 1:48 pm Post subject: Handling zero selected rows in query itself - for Inner quer |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Jul 21, 2009 2:28 pm Post subject: |
|
|
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 |
|
 |
seekaysk Beginner
Joined: 31 Aug 2007 Posts: 49 Topics: 15
|
Posted: Wed Jul 22, 2009 8:29 am Post subject: |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
seekaysk Beginner
Joined: 31 Aug 2007 Posts: 49 Topics: 15
|
Posted: Wed Jul 22, 2009 3:00 pm Post subject: |
|
|
great. thanks again for the extended help. This is a very handy doc. _________________ Thanks. |
|
Back to top |
|
 |
|
|