IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SQL question


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
beginner

New User


Joined: 30 Jun 2006
Posts: 1

PostPosted: Tue Jul 04, 2006 5:38 pm
Reply with quote

Hi,

I need help regarding the SQL that I am creating.

Actually it's a query. Given a combination of criteria, the SQL should be able to return the record that meets the highest criteria.

Ex:
Record 1 = passes hierarcy 3
Record 2 = passes hierarcy 2
Record 3 = passes hierarcy 1
So when the SQL is executed it should be able to return Record 3.

I'm required not to use a user defined SQL function and I should be able to use one SQL to perform such requirement.

I tried the following SQL

SELECT * FROM
(SELECT NVL(ID,'NONE')
FROM TABLE A, TABLE B
WHERE A.ID = B.ID
AND B.TYPE = HIERARCY 1),
(SELECT NVL(ID,'NONE')
FROM TABLE A, TABLE B
WHERE A.ID = B.ID
AND B.TYPE = HIERARCY 2),
(SELECT NVL(ID,'NONE')
FROM TABLE A, TABLE B
WHERE A.ID = B.ID
AND B.TYPE = HIERARCY 3)

I was expecting that this SQL will return an ID if the select criteria has been met and a 'NONE' value otherwise. This works fine when all 3 select statements have been met. But when one of the select doesn't return an ID, the whole select returns 3 NULL values (one for each select statement).

Can anyone please please help me?
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Jul 07, 2006 3:48 am
Reply with quote

You have us somewhat confused as to what you're trying to do. Can you please give us more information about the table structure, and some examples of data in the table. Please come back, we would like to assist if we can.

Dave
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Question for file manager IBM Tools 7
No new posts question for Pedro TSO/ISPF 2
No new posts question on Outrec and sort #Digvijay DFSORT/ICETOOL 20
No new posts panel creation question TSO/ISPF 12
No new posts Sort w/OUTREC Question DFSORT/ICETOOL 2
Search our Forums:

Back to Top