Monday, March 18, 2013

Dynamics GP SQL View - Basic SOP History


SELECT     dbo.SOP30300.ITEMNMBR, CASE WHEN sop30200.soptype = 4 THEN sop30300.XTNDPRCE * - 1 ELSE sop30300.xtndprce END AS ExtPrice,
                      CASE WHEN sop30200.soptype = 4 THEN sop30300.extdcost * - 1 ELSE sop30300.extdcost END AS ExtCost, dbo.SOP30300.NONINVEN, dbo.SOP30300.SOPTYPE,
                      CASE WHEN sop30200.soptype = 4 THEN sop30300.quantity * - 1 ELSE sop30300.quantity END AS Qty, dbo.SOP30300.UOFM, dbo.SOP30200.GLPOSTDT,
                      dbo.SOP30200.VOIDSTTS, dbo.SOP30200.SLPRSNID AS DocSrID, MONTH(dbo.SOP30200.GLPOSTDT) AS GlPostMth, YEAR(dbo.SOP30200.GLPOSTDT) AS GlPostYr,
                      dbo.SOP30300.SOPNUMBE, DATENAME(MM, dbo.SOP30200.GLPOSTDT) AS GlMonthName, dbo.SOP30300.QTYBSUOM, dbo.SOP30300.SLPRSNID AS LineSrID
FROM         dbo.SOP30200 INNER JOIN
                      dbo.SOP30300 ON dbo.SOP30200.SOPNUMBE = dbo.SOP30300.SOPNUMBE AND dbo.SOP30200.SOPTYPE = dbo.SOP30300.SOPTYPE
WHERE     (dbo.SOP30200.SOPTYPE IN ('3', '4')) AND (YEAR(dbo.SOP30200.GLPOSTDT) >= YEAR(GETDATE()) - 2) AND (dbo.SOP30200.VOIDSTTS = 0) AND
                      (dbo.SOP30300.NONINVEN = 0)

No comments:

Post a Comment