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

Problem in SQL query : CASE expression


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

New User


Joined: 17 Jun 2009
Posts: 6
Location: Hyderabad

PostPosted: Fri Aug 07, 2009 10:30 am
Reply with quote

Dear All,

I'm facing problem while writing a cursor for a stored procedure.
The query which i given is only part of query and facing problem in the below scenario.
The requirement is like this:

Code:
SELECT T1.C1
      ,CASE WHEN T1.C1 = 'ACTIVE'
       THEN 'ACTIVE'
       ELSE 'INACTIVE'
       END AS STATUS_FINAL
FROM (SELECT CASE WHEN
                      ( SELECT 'Y'
                          FROM ABCD.TABLE2 T2
                         WHERE T2.COL1 = 'XXXX'
                        AND ..OTHER CONDITIONS ) = 'Y'
             THEN 'ACTIVE'
             ELSE 'INACTIVE'
             END AS C1
       FROM SYSIBM.SYSDUMMY1
       FETCH FIRST 1 ROW ONLY) T1
WITH UR;
Code'd


The above query is working fine.
when i'm selecting 2 more columns for TABLE2
then i'm unable to get check the same condition......as given below.

SELECT T1.C1
,T2.C2
,T2.C3

,CASE WHEN T1.C1 = 'ACTIVE'
THEN 'ACTIVE'
ELSE 'INACTIVE'
END AS STATUS_FINAL
FROM (SELECT CASE WHEN
( SELECT 'Y'
,T2.C2
,T2.C3

FROM ABCD.TABLE2 T2
WHERE T2.COL1 = 'XXXX'
AND ..OTHER CONDITIONS ) = 'Y'
THEN 'ACTIVE'
ELSE 'INACTIVE'
END AS C1
FROM SYSIBM.SYSDUMMY1
FETCH FIRST 1 ROW ONLY) T1
WITH UR;

If the sqlcode is 0 then C2 & C3 should have actual value
ELSE if 100, then column C2 & C3 should be spaces.


Your help is much appreciated.

Regards
Rindia
Back to top
View user's profile Send private message
Rindia

New User


Joined: 17 Jun 2009
Posts: 6
Location: Hyderabad

PostPosted: Fri Aug 07, 2009 10:55 am
Reply with quote

In other conditions ORDER BY clause exits.
Back to top
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Fri Aug 07, 2009 12:14 pm
Reply with quote

SELECT T1.C1
,T2.C2
,T2.C3
,CASE WHEN T1.C1 = 'ACTIVE'
THEN 'ACTIVE'
ELSE 'INACTIVE'
END AS STATUS_FINAL
FROM (SELECT CASE WHEN
( SELECT 'Y'
,T2.C2
,T2.C3
FROM ABCD.TABLE2 T2
WHERE T2.COL1 = 'XXXX'
AND ..OTHER CONDITIONS ) = 'Y'
THEN 'ACTIVE'
ELSE 'INACTIVE'
END AS C1
FROM SYSIBM.SYSDUMMY1
FETCH FIRST 1 ROW ONLY) T1
WITH UR


Please check this bold condition....how can you compare three values with one =Y.... icon_idea.gif
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
Search our Forums:

Back to Top