Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Rows to be extracted based on condition

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Fri Mar 23, 2012 2:11 am    Post subject: Rows to be extracted based on condition
Reply with quote

Hi All,

I have 2 tables with data spread as follows:

TABLE A
Code:

Acct ID   Item    State  Pol Eff Date
 1111      100     FL    2012-01-01       
 2222      200     FL    2011-01-01       
 3333      300     FL    2012-04-01       
 4444      500     KY    2012-05-01


TABLE B
Code:
Acct ID   Item  Code
 1111     100   10
 2222     200   10
 3333     300   20
 4444     500   10


Table A and Table B has Acct and Item as common field
I wanted to extract all the accounts from Table A joining with Table B but should skip the accounts whose State is FL having Code 10 with effective date greater than or equal to 2012-01-01. That means I should exclude the above mentioned accounts but include FL accounts with code 10 prior to 2012-01-01 or FLORIDA accounts with code other than 10 irrespective of eff date. This condition is only for FL state. Accounts of other state should be included without any condition.

SQL in my mind whch is not working is

Code:
SELECT A.ACCT_ID,A.ITEM,A.STATE,A.POL_EFF_DATE,B.CODE
   FROM TABLE A
            INNER JOIN
            TABLE B
       ON A.ACCT_ID = B.ACCT_ID
      AND A.ITEM = B.ITEM
      AND .......


Result should be
Code:
Acct ID   Item State  Pol Eff Date Code 
 2222      200  FL    2011-01-01    10 
 3333      300  FL    2012-04-01    20   
 4444      500  KY    2012-05-01    10 

Can somebody please guide me here ?

Thanks
Vinu
Back to top
View user's profile Send private message

vinu78

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Fri Mar 23, 2012 2:23 am    Post subject:
Reply with quote

I think I got the solution.

I believe the following will work

Code:
SELECT A.ACCT_ID,A.ITEM,A.STATE,A.POL_EFF_DATE,B.CODE
  FROM TABLE A
           INNER JOIN
           TABLE B
     ON A.ACCT_ID = B.ACCT_ID
   AND A.ITEM = B.ITEM
   AND NOT (A.STATE = FL AND B.CODE = 10
                  AND A.POL_EFF >='2012-01-01')


Sorry, I didn't think of the NOT function
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 Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 1 Wed Dec 06, 2017 1:50 am
No new posts Can we combine the rows with same key... V S Amarendra Reddy DB2 12 Fri Dec 01, 2017 10:29 pm
No new posts Split files upto certain limit based ... bubbu75 DFSORT/ICETOOL 5 Tue Nov 14, 2017 11:11 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Execute JCL step based on the content... sprikitik JCL & VSAM 2 Tue Oct 03, 2017 10:03 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us