Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SQL question

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: SQL question
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    Post subject: Re: SQL question
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fault Analyzer - listings question. egrove IBM Tools 4 Thu Aug 11, 2016 5:31 pm
No new posts dataset copy question - REPRO or some... atulxp TSO/ISPF 2 Wed Aug 03, 2016 10:56 pm
No new posts SQL Order By related question Joseph K Thomas DB2 8 Fri Mar 18, 2016 12:53 pm
No new posts DFSort Question krrp DFSORT/ICETOOL 9 Mon Mar 07, 2016 7:11 pm
No new posts Question: REORG on LOB tablespaces rakesh1155 DB2 1 Fri Aug 14, 2015 2:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us