I need all open invoices, matching invoices and invoices from pendingtable for a given mbr-id
I need below columns in output
invoice-no,tot-amnt,pend-invoice-no,pend-amnt
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
Posted: Wed Oct 05, 2011 4:29 pm Post subject:
SK2007,
Try this sql(untested)
Code:
SELECT INVOICE_NO AS INVOICE_NO
,TOT_AMNT AS TOT_AMNT
,PEND_INVOICE_NO AS PEND_INVOICE_NO
,PEND_AMNT AS PEND_AMNT
FROM OPEN_TABLE
,PEND_TABLE
WHERE MBR_ID = 1234567
AND INVOICE_NO = PEND_INVOICE_NO
UNION
SELECT NULLIF(1,1) AS INVOICE_NO
,NULLIF(1,1) AS TOT_AMNT
,PEND_INVOICE_NO AS PEND_INVOICE_NO
,PEND_AMNT AS PEND_AMNT
FROM PEND_TABLE
WHERE (PEND_MBR_ID,PEND_INVOICE_NO) NOT IN (SELECT MBR_ID
,INVOICE_NO
FROM OPEN_TABLE
WHERE MBR_ID =1234567)
AND PEND_MBR_ID = 1234567
UNION
SELECT INVOICE_NO AS INVOICE_NO
,TOT_AMNT AS TOT_AMNT
,NULLIF(1,1) AS PEND_INVOICE_NO
,NULLIF(1,1) AS PEND_AMNT
FROM OPEN_TABLE
WHERE (MBR_ID,INVOICE_NO) NOT IN (SELECT PEND_MBR_ID
,PEND_INVOICE_NO
FROM PEND_TABLE
WHERE PEND_MBR_ID =1234567)
AND MBR_ID = 1234567
;
SELECT A.INVOICE_NO
,A.TOT_AMNT
,B.PEND_INVOICE_NO
,B.PEND_AMNT
FROM (select * from OPEN_TABLE where mbr_id =1234567) A
full outer join
(select * from PEND_TABLE where pend_mbr_id =1234567) B
on A.INVOICE_NO = B.PEND_INVOICE_NO
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum