I needed to check how many serial numbers were assigned to sales transactions and the cumulative length of them. I’m not aware of any function in Microsoft Dynamics GP which would give me this information, so I wrote the below SQL statement to return both values along with the transaction type and document number.
It selects from the Sales Serial/Lot Work and History (SOP10201) table which, allowing for a simple statement, includes both the work and history data (SOP transactions don’t have a status of open).
/*
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
SOP.SOPNUMBE AS 'SOP Number'
,SOP.SOPTYPE AS 'SOP Type'
,SOP.LNITMSEQ AS 'Line Item Sequence'
,COUNT(1) AS 'Serial Number Count'
,SUM(LEN(SOP.SERLTNUM)) AS 'Serial Number Length'
FROM
SOP10201 AS SOP -- Sales Serial/Lot Work and History (SOP10201)
GROUP BY
SOP.SOPNUMBE
,SOP.SOPTYPE
,SOP.LNITMSEQ
ORDER BY
SUM(LEN(SOP.SERLTNUM)) DESC