Wednesday, April 30, 2014

Sub select query Help

I have to do a task of finding records which matches the following logic.


My table has PID varchar(15), Amount varchar (50),Status varchar(20) columns.


Each PID can go thru changes in a period of time, in my case i dont have a data range I just have a flatfile which consists of three types of PID`s


123456 = Original_PID, Reversal =123456R1,Adjustment= 123456A1.


Basically What I am trying to find out if there are any original PID`s which has a Reversal or an Adjustment.


here`s the code I have started on... Can someone help me get it finished?



select R1. pid,a1.pid,org.pid from (



select SUBSTRING(Pid,1,11)as Original_PID, status, paid_amount as Amount from dbo.Q2STATUS)org

inner join (select SUBSTRING(Pid,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
where SUBSTRING(Pid,12,2) ='R1')r1 on r1.pid=org.pid

inner join (select SUBSTRING(claim_id,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
where SUBSTRING(Pid,12,2) ='A1')A1 on a1.Pid=org.PID





FM


No comments:

Post a Comment