This script is part of the SQL Scripts for Microsoft Dynamics GP where I will be posted the scripts I wrote against Microsoft Dynamics GP over the 19 years before I stopped working with Dynamics GP.
This script returns a list of payables management invoices for vendors who also have purchase orders.
/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/
SELECT
['Payables Transactions'].VENDORID AS 'Control Type'
,['Payables Transactions'].VENDORID AS 'Vendor ID'
,['Payables Transactions'].VCHRNMBR AS 'Voucher Number'
,['Payables Transactions'].DOCTYPE AS 'Document Type'
,['Payables Transactions'].TRXDSCRN AS 'Description'
,['Payables Transactions'].DOCDATE AS 'Document Date'
,['Payables Transactions'].DOCNUMBR AS 'Document Number'
,['Payables Transactions'].DOCAMNT AS 'Document Amount'
,['Purchase Orders'].POCOUNT AS 'Count of POs'
FROM
(
SELECT
CNTRLTYP
,DOCTYPE
,VCHRNMBR
,TRXDSCRN
,VENDORID
,DOCDATE
,DOCNUMBR
,DOCAMNT
,PORDNMBR
,BCHSOURC
FROM
PM20000 AS PM WITH (NOLOCK)
WHERE
DOCTYPE = 1
AND
BCHSOURC = 'PM_Trxent'
UNION ALL
SELECT
CNTRLTYP
,DOCTYPE
,VCHRNMBR
,TRXDSCRN
,VENDORID
,DOCDATE
,DOCNUMBR
,DOCAMNT
,PORDNMBR
,BCHSOURC
FROM
PM30200 AS PM WITH (NOLOCK)
WHERE
DOCTYPE = 1
AND
BCHSOURC = 'PM_Trxent'
) AS ['Payables Transactions']
INNER JOIN
(
SELECT
VENDORID
,SUM(POCOUNT) AS POCOUNT
FROM
(
SELECT
VENDORID
,COUNT(PONUMBER) AS POCOUNT
FROM
POP10100 WITH (NOLOCK)
GROUP BY
VENDORID
UNION
SELECT
VENDORID
,COUNT(PONUMBER) AS POCOUNT
FROM
POP30100 WITH (NOLOCK)
GROUP BY
VENDORID
) AS ['Purchase Orders']
GROUP BY
VENDORID
) AS ['Purchase Orders']
ON
['Purchase Orders'].VENDORID = ['Payables Transactions'].VENDORID
WHERE
['Purchase Orders'].POCOUNT > 0
GO
Click to show/hide the SQL Scripts for Microsoft Dynamics GP Series Index
What should we write about next?
If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.
Looking for support or consultancy with Microsoft Dynamics GP?
I no longer work with Microsoft Dynamics GP, but the last company I worked for was ISC Software in the UK; if you’re looking for support or consultancy services with Microsoft Dynamics GP you can contact them here.