Thursday, November 27, 2014

Dynamics GP - SQL VIEW - PO, Received status, Invoiced status

SELECT     POP10100.PONUMBER, a.POPRCTNM, a.VNDDOCNM, a.APStatus, a.BCHSOURC, a.VCHRNMBR, PM00200.VENDORID, PM00200.VENDNAME,
                      CASE WHEN poprctnm IS NOT NULL THEN 'Received' ELSE 'Not Received' END AS RctStatus, CASE WHEN vchrnmbr IS NOT NULL
                      THEN 'Invoiced' ELSE 'Not Invoiced' END AS InvStatus
FROM         POP10100 LEFT OUTER JOIN
                      PM00200 ON POP10100.VENDORID = PM00200.VENDORID LEFT OUTER JOIN
                          (SELECT     'Work' AS APStatus, POP10300.POPRCTNM, POP10300.VNDDOCNM, POP10300.BCHSOURC, POP10310.RCPTLNNM,
                                                   POP10310.PONUMBER, POP10300.VENDORID, POP10300.VCHRNMBR, POP10310.ITEMDESC, POP10310.ITEMNMBR
                            FROM          POP10300 INNER JOIN
                                                   POP10310 ON POP10300.POPRCTNM = POP10310.POPRCTNM
                            UNION
                            SELECT     'Posted' AS APstatus, POP30300.POPRCTNM, POP30300.VNDDOCNM, POP30300.BCHSOURC, POP30310.RCPTLNNM,
                                                  POP30310.PONUMBER, POP30300.VENDORID, POP30300.VCHRNMBR, POP30310.ITEMDESC, POP30310.ITEMNMBR
                            FROM         POP30300 INNER JOIN
                                                  POP30310 ON POP30300.POPRCTNM = POP30310.POPRCTNM) AS a ON POP10100.PONUMBER = a.PONUMBER
GROUP BY a.APStatus, a.POPRCTNM, a.VNDDOCNM, a.BCHSOURC, a.VCHRNMBR, POP10100.PONUMBER, PM00200.VENDORID, PM00200.VENDNAME

No comments:

Post a Comment