How can i join PO with GRPO

Hi,
I make query as belown to join PO with GRPO.I wnat to calculate Quantity from PO to GRPO but in my query it show duplicate record i also use distinct but useless.My query as below.
SELECT T1.DocNum [PO No], T1.DocDate [PO Date], T3.ItemCode, T3.Dscription, T3.U_CostCentre, T3.DocEntry [GRN No], T0.DocDate [GRN Date],T3.Quantity'GRIR Quantity',T2.Quantity 'PO Quantity',
T3.Quantity-T2.Quantity 'Balance Quantity'
FROM OPDN T0 , OPOR T1, POR1 T2, PDN1 T3
WHERE T1.DocEntry = T2.DocEntry
and T0.Docnum = T3.Docentry
and T3.BaseRef  =  T1.DocNum
and T2.ItemCode = T3.ItemCode
and T3.DocDate between [%0] and [%1]
Can any body help in this regards.
Sohail Anwar Ali

Hi Sohail,
As i understand, you want to know till now how much of quantity stills needs  to be delivered, in that case instead of trying joining two tables i would suggest to try this query which gives you
Purchase Order Document No,
Purchase Order Date,
Vendor Name,
Item Code,
Item Description,
Ordered Quantity,
Received Quantity,
Open Quantity.
as the filed OpenQty stores the Quantity yet to receive for that particular Purchase Order. As this approach is much more flexible
Query
SELECT T0.DocNum, T0.DocDate, T0.CardName, T1.ItemCode, T1.Dscription, T1.Quantity,
(T1.Quantity-T1.OpenQty) as "Recevied Quantity",
T1.OpenQty FROM OPOR T0  INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocDate >=[%0] and
T0.DocDate <=[%1]
I hope this helps out your issue
regards,
Shreyas

Similar Messages

  • How can i join table with multiple colums

    This is my Data-----------------------------------------------------DECLARE @StockIn TABLE
    InID INT ,
    StockID INT ,
    InQty DECIMAL(16, 2) ,
    Price DECIMAL(16, 2) ,
    tranDate DATE ,
    running INT
    DECLARE @StockOut TABLE
    OutID INT ,
    StockID INT ,
    OutQty DECIMAL(16, 2) ,
    lineid INT ,
    tranDate DATE
    INSERT INTO @StockIn ( InID, StockID, InQty, Price, tranDate, running )
    VALUES ( 1, 1, 15, 430, '2014-10-09', 1 ),
    ( 2, 1, 10, 431, '2014-10-10', 2 ),
    ( 3, 1, 15, 432, '2015-02-02', 3 ),
    ( 4, 2, 15, 450, '2014-08-05', 1 ),
    ( 5, 2, 6, 450, '2014-10-01', 2 ),
    ( 6, 2, 15, 452, '2015-10-02', 3 )
    INSERT INTO @StockOut ( OutID, StockID, OutQty, lineid, tranDate )
    VALUES ( 1, 1, 20, 2, '2014-10-11' ),
    ( 2, 1, 10, 4, '2014-10-12' ),
    ( 3, 2, 12, 8, '2014-11-01' ),
    ( 4, 2, 3, 8, '2014-11-02' );--------------------------------------------------------------------This is my query for calculate the total remaining of stock of any stockID--------------------------------------------------------------------                    WITH  RunningTotals as (
    select StockID , Qty , price , total , total - qty AS PrevTotal, TranDate , rn FROM (
    select 
     StockID, InQty  AS QTY , Price 
    , SUM(InQty) over (PARTITION BY StockID order by tranDate ,  inQty DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as Total
    ,ROW_NUMBER() OVER (PARTITION BY StockID ORDER BY  tranDate ,  inQty DESC ) as rn
    ,TranDate --,TranID, TxnType
    from @StockIn  )  A   -- runing stockID in stock order by tranDate
    ) , TotalOut as ( 
    SELECT    StockID ,  Sum(OutQty) AS QTY
    FROM            @StockOut 
       GROUP BY StockID  -- Sum of outQty group by StockID
    ) ,  GrandTotal as 
    select
    rt.StockID , rt.QTY AS original ,SUM(CASE WHEN PrevTotal > isNULL(out.Qty, 0) THEN rt.Qty ELSE rt.Total - isNULL(out.Qty, 0) END) AS QTY , Price , SUM(CASE WHEN PrevTotal > isNULL(out.Qty, 0) THEN rt.Qty ELSE rt.Total - isNULL(out.Qty, 0) END * Price) AS Ending , rt.TranDate  from 
    RunningTotals rt
    left join
    TotalOut out
    on
    rt.StockID = out.StockID 
    where rt.Total > isNull(out.Qty , 0)
    group by rt.StockID , Price , rt.TranDate  , rt.QTY  -- running OutQty out of inQty of any stockID
    ) Select * from GrandTotal order by stockID ------------------------------------------------------------
    This query is run the total remaining of stock exactly right. But if i try to get the OutQty of stockID of any Line (lineid)The query duplicate data. this is Example------------------------------------------------------------                    DECLARE @StockIn TABLE
          InID INT ,
          StockID INT ,
          InQty DECIMAL(16, 2) ,
          Price DECIMAL(16, 2) ,
          tranDate DATE ,
          running INT
    DECLARE @StockOut TABLE
          OutID INT ,
          StockID INT ,
          OutQty DECIMAL(16, 2) ,
          lineid INT ,
          tranDate DATE
    INSERT  INTO @StockIn ( InID, StockID, InQty, Price, tranDate, running )
    VALUES  ( 1, 1, 15, 430, '2014-10-09', 1 ),
            ( 2, 1, 10, 431, '2014-10-10', 2 ),
            ( 3, 1, 15, 432, '2015-02-02', 3 ),
            ( 4, 2, 15, 450, '2014-08-05', 1 ),
            ( 5, 2, 6, 450, '2014-10-01', 2 ),
            ( 6, 2, 15, 452, '2015-10-02', 3 )
    INSERT  INTO @StockOut ( OutID, StockID, OutQty, lineid, tranDate )
    VALUES  ( 1, 1, 20, 2, '2014-10-11' ),
            ( 2, 1, 10, 4, '2014-10-12' ),
            ( 3, 2, 12, 8, '2014-11-01' ),
            ( 4, 2, 3, 8, '2014-11-02' );
    WITH  RunningTotals as (
    select StockID , Qty , price , total , total - qty AS PrevTotal, TranDate , rn FROM (
    select 
     StockID, InQty  AS QTY , Price 
    , SUM(InQty) over (PARTITION BY StockID order by tranDate ,  inQty DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as Total
    ,ROW_NUMBER() OVER (PARTITION BY StockID ORDER BY  tranDate ,  inQty DESC ) as rn
    ,TranDate --,TranID, TxnType
    from @StockIn  )  A  
    ) , TotalOut as ( 
    SELECT    StockID ,  Sum(OutQty) AS QTY , lineid -- Group by stockID of any lineidFROM            @StockOut 
       GROUP BY StockID   , lineid
    ) ,  GrandTotal as 
    select
    rt.StockID , rt.QTY AS original ,SUM(CASE WHEN PrevTotal > isNULL(out.Qty, 0) THEN rt.Qty ELSE rt.Total - isNULL(out.Qty, 0) END) AS QTY , Price , SUM(CASE WHEN PrevTotal > isNULL(out.Qty, 0) THEN rt.Qty ELSE rt.Total - isNULL(out.Qty, 0) END * Price) AS Ending , rt.TranDate , lineid from 
    RunningTotals rt
    left join
    TotalOut out
    on
    rt.StockID = out.StockID 
    where rt.Total > isNull(out.Qty , 0)
    group by rt.StockID , Price , rt.TranDate  , rt.QTY   , lineid
    ) Select * from GrandTotal order by stockID ----------------------------------------------How can i running the total out (OutQty*price) of any lineid

    Check this query, the date is excluded because it cannot return the result you want with and it will not be of any value to read the date like that in such a query:
    DECLARE @StockIn TABLE
    InID INT ,
    StockID INT ,
    InQty DECIMAL(16, 2) ,
    Price DECIMAL(16, 2) ,
    tranDate DATE ,
    running INT
    DECLARE @StockOut TABLE
    OutID INT ,
    StockID INT ,
    OutQty DECIMAL(16, 2) ,
    lineid INT ,
    tranDate DATE
    INSERT INTO @StockIn ( InID, StockID, InQty, Price, tranDate, running )
    VALUES ( 1, 1, 15, 430, '2014-10-09', 1 ),
    ( 2, 1, 10, 431, '2014-10-10', 2 ),
    ( 3, 1, 15, 432, '2015-02-02', 3 ),
    ( 4, 2, 15, 450, '2014-08-05', 1 ),
    ( 5, 2, 6, 450, '2014-10-01', 2 ),
    ( 6, 2, 15, 452, '2015-10-02', 3 )
    INSERT INTO @StockOut ( OutID, StockID, OutQty, lineid, tranDate )
    VALUES ( 1, 1, 20, 2, '2014-10-11' ),
    ( 2, 1, 10, 4, '2014-10-12' ),
    ( 3, 2, 12, 8, '2014-11-01' ),
    ( 4, 2, 3, 8, '2014-11-02' );
    WITH RunningTotals as (
    select StockID , Qty , price , total , total - qty AS PrevTotal, TranDate , rn FROM (
    select
    StockID, InQty AS QTY , Price
    , SUM(InQty) over (PARTITION BY StockID order by tranDate , inQty DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as Total
    ,ROW_NUMBER() OVER (PARTITION BY StockID ORDER BY tranDate , inQty DESC ) as rn
    ,TranDate --,TranID, TxnType
    from @StockIn ) A
    ) , TotalOut as (
    SELECT StockID , Sum(OutQty) AS QTY , lineid -- Group by stockID of any lineid
    FROM @StockOut
    GROUP BY StockID , lineid
    ) , GrandTotal as
    select
    rt.StockID , rt.QTY AS original ,SUM(CASE WHEN PrevTotal > isNULL(out.Qty, 0) THEN rt.Qty ELSE rt.Total - isNULL(out.Qty, 0) END) AS QTY , Price , SUM(CASE WHEN PrevTotal > isNULL(out.Qty, 0) THEN rt.Qty ELSE rt.Total - isNULL(out.Qty, 0) END * Price) AS Ending , rt.TranDate , lineid from
    RunningTotals rt
    left join
    TotalOut out
    on
    rt.StockID = out.StockID
    where rt.Total > isNull(out.Qty , 0)
    group by rt.StockID , Price , rt.TranDate , rt.QTY , lineid
    ) Select Distinct StockID,(select sum(original) from GrandTotal G where G.lineid = GrandTotal.lineid) as original,(select sum(QTY) from GrandTotal G where G.lineid = GrandTotal.lineid) as QTY,
    (select sum(Price) from GrandTotal G where G.lineid = GrandTotal.lineid) as Price, (select sum(Ending) from GrandTotal G where G.lineid = GrandTotal.lineid) as Ending,lineid from GrandTotal
    order by stockID
    the result will be:
    StockID original QTY Price Ending lineid
    1 25.00 20.00 863.00 8635.0000 2
    1 40.00 30.00 1293.00 12940.0000 4
    2 21.00 21.00 902.00 9480.0000 8
    Fouad Roumieh

  • How can I join PRPS with DRAD?

    Hi,
    I would like to join the table PRPS and DRAD in order to see all documents linked to a certain PSP. I tried to join DRADOBJKY with PRPSPSPNR but it doesn't work since the OBJKY is different from the psp-number. If I'm doing this with MARA~MATNR it works. Strange. can someboy help me?
    Thanks

    Hello,
    Can you check if PRPS-OBJNR = DRAD-OBJKY ?
    If this is not successful, then use the conv. exit  CONVERSION_EXIT_ABPSP_INPUT, pass the PRPS-OBJNR get the internal number.
    Now check that this internal number matches with DRAD-OBJKY.
    Plz revert back.
    BR,
    Suhas

  • I can not join my Apple extreme with the Apple express. I shows a conflict in the network! I've tried everything. How can they join on the same network?

    I can not join my Apple extreme with the Apple express. I shows a conflict in the network! I've tried everything. How can they join on the same network?

    It says that my DHCP has to be changed! How? to what?
    It is 802.11g.express. but is set to default by the computer (Macbook Air).
    The other is 802.11n. (express)
    Extreme is 802.11.g. Is the Main Airport.
    It is on ethernet & wep 128 security.

  • HT4623 How can I join 2 separate account one for my IPhone and one to my IPad to one account with the same ID and Password?

    How can I join 2 separate account one for my IPhone and one to my IPad to one account with the same ID and Password?

    You cannot combine two different Apple ID's into one ID.

  • Can you please help me by saying me how can i join two different picture to make it as one picture.??

    Hi Sir/ Madam,
       My name is Rishav and I am facing some problem with my Photoshop CC. Actually I have a question. If you guys could help me out i will be very obliged. The quest in "Can you please help me by saying me how can i join two different picture to make it as one picture.??"

    Maybe you should post over at
    Photoshop for Beginners
    or start with the "Get Started" section of the Help:
    Photoshop Help | Photoshop Help
    And your question
    Can you please help me by saying me how can i join two different picture to make it as one picture.??
    does not seem particularly specific – do you want to simply combine two images as they are, do you want to clip elements from the one and insert them into the other, …?
    Could you post (lores of) the images and explain what you intend to achieve?

  • How can i build table with two user name columne  ?

    How can I build view with two columns for user name ( one create and the other
    Can change also ) 
    And to display full name ( the user name is the key but not display  ) ?

    Hi,
    Creating View
    •     From initial screen of data dictionary(T.Code: SE11), enter the name of object i.e. view.
    •     Select view radio button and click on the push button.
    •     Dialog box is displayed for types of views.
    •     Select the view type.
    •     On the next screen, you have to pass following parameters.
    •     Short text
    •     In the table box you need to enter the table names, which are to be related.
    •     In join table box you need to join the two tables.
    •     Click on the TABFIELD. System displays the dialog box for all the table fields and user can select the fields from this screen. These fields are displayed in the view fields box.
    •     Save and Activate: When the view is activated, view is automatically created in the underlying database system. As long as the table exists in the database, the view also exists (Unless you delete it).
    Regards,
    Bhaskar

  • Can we join table with structure

    Hi
    i have taken fields from Plaf table and some fields from structures so now i want to join that how can i join.
    Is there any option?
    regards

    Hi,
    structure dont have any data base table associated with them so they dont have any data.
    that's why we cannot join structure witha table but we can include a structure within any table.
    Sytex to include structure in ztable:
    fieldname     data element.
    .include        struname
    hope it will ans ur query.
    Thanks
    Rajesh Kumar

  • How can I join a conversation?

    how can i join ur conversation now? pls...reply
    [Topic title updated by moderator to be more descriptive. Original topic title was: "charisse"]

    Cat_Unicorns_x wrote:
    Hi,
    I want to delete a conversation with a friend, but I don't want to delete the actual contact (or block them or anything). I only want that one conversation gone, I know how to delete ALL my messages and call history and that (I've done that before). I looked for a while but found nothing.
    Please help!!
    Thanks,
    Cat_Unicorns_x 
    Unfortunately, such option does not exist directly in Skype. However, if you are not afraid to use a SQLite database editor, you can try to delete this message from the chat database.
    http://community.skype.com/t5/General-Discussion/Delete-a-conversation/m-p/743928#M43908

  • How can i join more than 20 tables which contains more than 5 lacks records

    how can i join more than 20 tables which contains more than 5 lacks records

    If you're trying to join 20 tables I would check:
    - Are all the joins necessary. It's easy sometimes to just join to another table because you're unsure as to whether it's required.
    - What sort of application is it? 20 joins seems a lot to me. Are you trying to achieve too much with one query? Is it possible to break the problem down?
    - If it is necessary to join so many tables then force the use of hash joins in the query, especially if you're processing a lot of data and want the best throughput. If you want a quicker response, this will not be a appropriate.

  • How can I join/merge audio in 1 step?

    How can I join/merge audio in 1 step? Or... 2 in Logic X.
    I want join all the audio in this track(image)

    I see only three steps, and one of 'm (3.) should not be necessary unless you've created a take folder or folder track somehow?
    In step 2. you are not joining tracks, but regions (on the track).
    I do understand why Apple does not "fix" this: nothing's broken, that's why. If the Logic dev team would listen to all these "it's too complicated" complaints, Logic Pro would eventually end up being iTunes with a record button.
    Two tips: learn the terminology (knowing the difference between tracks and regions, for starters) and use the search function in the manual. If that still doesn't get you anywhere, ask us.
    Have a nice day!

  • How can i join two libraries from two different users

    how can i join two libraries from two different users in the same computer?

    I should add that you can turn on SHARING where each user can see the other user's library and play stuff out of it. But they can not import those tracks to their own library or put them into their own playlists or burn CDs of the shared library.
    Also note, to do this you need to have the fast switching option enabled with the accounts so both can be running at the same time and both must have iTunes running at the same time.
    Patrick

  • How can I join a community

    Hi all,  i know this may not be the right path to post this question,  but can u pl tell me how can i join a community like for ex wipro or tcs so that i can be listed there with my contribution points if i submit my piece of code.  pl tell me procedure since i am new to sdn

    How to Contribute   My Profile
    on Top of the forum there is an option to update your profile, Just click the menu My Profile and change your mail according to your company address.

  • Can we join Ztables with SAP std. tables in SQVI ?

    Dear All,
    Can we join Ztables with SAP std. tables in SQVI ?
    How to use "left outer join" in SQVI ?
    What r the rules/steps to be followed for creating right SQVI/query ?
    Sometimes it gives error / we do not get any output ....
    Pl' give examples.

    hi
    good
    1- Yes
    3-Check this example for SQVI Query.
    It is possible to generate a complete list of purchase document releases with the purchase document number (requisitions and orders), releaser, release date and release time.
    First, create an Infoset using transaction SQ02 directly reading from table CDPOS and create an additional table: CDHDR. If you are releasing purchase requsitions at the item level, it is convenient to create an additional field (PURPS LIKE EBAN-BNFPO) to capture the item number. Once the field is defined add the following code to it:
    PURPS = CDPOS-TABKEY+14(5).
    Once created, make sure to assign your Infoset to the user groups.
    Second, create an SAP Query (SQ00) or QuickViewer (SQVI) based on the Infoset you created previously. Set CDPOS-OBJECTID, PURPS (additional field), CDHDR-USERNAME, CDHDR-UDATE & CDHDR-UTIME, CDPOS-TCODE, CDPOS-VALUE_NEW, and CDPOS-VALUE_OLD as list fields (display screen).
    Set CDPOS-OBJECTCLAS, CDPOS-OBJECTID, CDPOS-TABNAME, CDPOS-FNAME, CDPOS-CHANGIND, CDHDR-USERNAME, CDHDR-UDATE & CDHDR-UTIME as the selection fields (selection screen).
    Finally, execute your query. For filtering purchase requisition releases set:
    Object class='BANF'
    Table Name='EBAN'
    Field Name='FRGKZ'
    Change type='U'
    For filtering purchase order releases set:
    Object class='EINKBELEG'
    Table Name='EKKO'
    Field Name='FRGKE'
    Change type='U'
    Make sure to specify username, dates or purchase document number (object value) in order to reduce run times.
    thanks
    mrutyun^

  • My iTunes library is missing since upgrade Lion 7.2.  I have it all backed up so that's not the issue. How can I reinstall it with all my hundreds of playlists intact or do I have to recreate each one upon reinstalling the backup copy? Thank you for help

    Almost my iTunes library is missing since upgrade Lion 7.2. (the last 2.5 weeks worth of added music has transferred post-upgrade, none of whcih was bought from iTunes)
    I have it all backed up so that's not the issue. How can I reinstall it with all my hundreds of playlists intact or do I have to recreate each playlist upon reinstalling the backup copy? This would save a HUGE amount of time and efforts. Thank you for your help!

    hi Limnos,
    I do not mean the entire ITunes folder but, rather, the contents of the ITunes folder prior to September 29th.  (90% of the media is missing, along with all playlists)  The media that remains says it was added on 9/29 although I know most of it was added many months or even years earlier. There are no playlists listed at all, before or after 9/29.  (I know for certain that I added non-iTunes purchased songs on 10/6 although I had not created playlists for them)
    I have my iTunes folder backed up on both an external drive as well as Time Machine.
    I run iTunes off of an ITunes folder on my computer rather than from the external, if that's what you mean about how I have it set up. 
    Is it OK to drag the entire iTunes folder from the external drive onto my laptop's drive and see if that fixes it?
    Thank you for your help!
    Deb

Maybe you are looking for

  • Pull records with PO indicator exist in Work orders

    I have  a requirement to  pull a  report which will show the number of work orders which have PO Exists indicator in the purchasing data when seen in IW32 for all nons tock components. Basically business wants to see those orders for which nonstock i

  • Just A Thought About Database I/O

    I was just thinking about the database in Lightroom and came upon a question that I hope I can ask clearly. Let's say I have an image open in the Develop module, and let's say that I click and drag on the Blacks slider. When I move that slider to mak

  • No extenson of saved file

    What am I doing wrongly? I've tried to save a certain set of edited photos (cropped, sharpened, enhanced, brightened, etc.) but they are not saving in proper format. I click on 'save as" choose format as 'jpg" when I go to find the photo, it's icon i

  • Thread Pool Executor ( Runnable Class Executing another Runnable Class )

    Hi Folks, I have my main class called ThreadPoolExecutorUser. I have two Runnable classes called XYZ and ABC in ThreadPoolExecutorUser class I execute the Runnable class XYZ. Which inturn executes Runnable class ABC. The problem is that the Runnable

  • Why does Apple keep changing the interface in iTunes?!

    I liked the interface in iTunes 10, but found that I liked the interface in iTunes 11 even better. It seemed that everything was organized a little better. But... now we are back to an interface like we had in iTunes 10. Do the developers think about