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

Help Needed in this Query


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

New User


Joined: 05 Dec 2006
Posts: 89
Location: chennai

PostPosted: Fri Dec 12, 2008 8:13 am
Reply with quote

Hi Team,
i have following requirement below,

Table1 contains invoiceid and date.
Table2 contains invoiceid and status.
Requirement --
Requirement is to match invoiceid in TABLE1 with TABLE2 and STATUS CODE =' A' AND STATUS CODE NOT EQUAL TO 'C ' OR 'D'

TABLE1

INVOICE ID DATE
1 2000
2 2001
4 2002

TABLE2

INVOICE ID STATUSCODE

1 A
1 B

2 A
2 B
2 C

3 A
3 B
3 D

4 A
4 D

OUTPUT
INVOICE ID DATE
1 2000

In above example,for invoice id '2' and '4' , status code = 'C' or 'D'.So it should not come in output.

can anyone please give me the query

Thanks
Jagadesh
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Dec 12, 2008 8:43 am
Reply with quote

itjagadesh,

This might be of some help to you(untested).

Code:
SELECT T1.INVOICE-ID,T1.DATE
  FROM TABLE1 T1
      ,TABLE2 T2
 WHERE T1.INVOICE-ID = T2.INVOICE-ID
   AND NOT EXISTS
       (SELECT 1
          FROM TABLE2 T3
         WHERE T3.INVOICE-ID = T1.INVOICE-ID
           AND T3.STATUSCODE IN ('C','D'))
Back to top
View user's profile Send private message
itjagadesh

New User


Joined: 05 Dec 2006
Posts: 89
Location: chennai

PostPosted: Fri Dec 12, 2008 9:14 am
Reply with quote

Hi Arun,

Thanks for your quick response.
But my requirement is to select STATUS CODE = 'A' also .

Requirement --
Requirement is to match invoiceid in TABLE1 with TABLE2 and STATUS CODE =' A' AND STATUS CODE NOT EQUAL TO 'C ' OR 'D'


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

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Fri Dec 12, 2008 9:27 am
Reply with quote

Hi,

I think below code will result in the desired output : ( Ustested )

Code:

Select a.invoice_id,a.invoice_dt from table1 a, table2 b
where a.invoice_id = b.invoice_id
      and b.invoice_st = 'A'
      and not exists (Select 1 from table2 c
                      where a.invoice_id = c.invoice_id
                            and c.invoice_st in ('C','D'));
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Fri Dec 12, 2008 9:43 am
Reply with quote

Quote:
Thanks for your quick response.
But my requirement is to select STATUS CODE = 'A' also .
I missed it. But you can modify it to add that condition.
Code:
SELECT T1.INVOICE-ID,T1.DATE
  FROM TABLE1 T1
      ,TABLE2 T2
 WHERE T1.INVOICE-ID = T2.INVOICE-ID
   AND T2.STATUSCODE = 'A'
   AND NOT EXISTS
       (SELECT 1
          FROM TABLE2 T3
         WHERE T3.INVOICE-ID = T1.INVOICE-ID
           AND T3.STATUSCODE IN ('C','D'))
Back to top
View user's profile Send private message
jitu852

New User


Joined: 30 Apr 2007
Posts: 27
Location: Hyderabad

PostPosted: Sun Dec 14, 2008 11:12 pm
Reply with quote

Hi,
if iam right no need of sub query it is simply
select columns,
from table1 t1,table2 t2
where t1.column1 =t2.column1
and t2.status = 'a'
Back to top
View user's profile Send private message
Rajesh Midde99

New User


Joined: 04 Dec 2008
Posts: 11
Location: Bangalore,India

PostPosted: Mon Dec 15, 2008 3:47 pm
Reply with quote

Hi

It will be help ful to others if the topic initiator responds if he is satisfied with the response and let every body know if the query is working or not ?? Please close the query with a response.

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

New User


Joined: 05 Dec 2006
Posts: 89
Location: chennai

PostPosted: Mon Dec 15, 2008 4:01 pm
Reply with quote

Hi All,
Thanks for your help.
Arun Query working fine.

Rajesh Sorry i was out of office.Not able to reply.


Thanks a lot to all.
Jagadesh
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 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
No new posts Query on edit primary command CLIST & REXX 1
No new posts Mainframe Programmer with CICS Skill... Mainframe Jobs 0
Search our Forums:

Back to Top