Friday, March 10, 2017

Dynamics GP - SQL Views - ItemMaster, ItemQty

SELECT     dbo.IV00101.ITEMNMBR, dbo.IV00101.ITEMDESC, dbo.IV00101.UOMSCHDL, dbo.IV40201.BASEUOFM, dbo.IV40201.UMDPQTYS, dbo.IV00101.ITMCLSCD, dbo.IV00101.CURRCOST, dbo.IV00101.ITMTRKOP, dbo.IV00101.LOTTYPE, dbo.IV00101.CREATDDT,
                  dbo.IV00101.MODIFDT, DATEDIFF(d, dbo.IV00101.CREATDDT, GETDATE()) AS AgeDays, dbo.IV40400.ITMCLSDC, dbo.IV00101.USCATVLS_1, dbo.IV00101.USCATVLS_2, dbo.IV00101.USCATVLS_3, dbo.IV00101.USCATVLS_4, dbo.IV00101.USCATVLS_5,
                  dbo.IV00101.USCATVLS_6, RTRIM(dbo.IV00101.ITEMNMBR) + ' | ' + RTRIM(dbo.IV00101.ITEMDESC) AS ItemLbl, LastDt.LastTrxDt,
                  CASE WHEN ITEMTYPE = 1 THEN 'Sales Inventory' WHEN ITEMTYPE = 2 THEN 'Discontinued' WHEN ITEMTYPE = 3 THEN 'Kit' WHEN ITEMTYPE = 4 THEN 'Misc Charges' WHEN ITEMTYPE = 5 THEN 'Services' WHEN ITEMTYPE = 6 THEN 'Flat Fee' END AS ItemTypeDesc,
                   dbo.IV00101.ITEMTYPE
FROM        dbo.IV00101 INNER JOIN
                  dbo.IV40201 ON dbo.IV00101.UOMSCHDL = dbo.IV40201.UOMSCHDL LEFT OUTER JOIN
                      (SELECT     ITEMNMBR, MAX(DOCDATE) AS LastTrxDt
                       FROM        dbo.IV10201
                       GROUP BY ITEMNMBR) AS LastDt ON dbo.IV00101.ITEMNMBR = LastDt.ITEMNMBR LEFT OUTER JOIN
                  dbo.IV40400 ON dbo.IV00101.ITMCLSCD = dbo.IV40400.ITMCLSCD

/****** Object:  View [dbo].[BI_ItemQty]    Script Date: 03/10/2017 09:13:50 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[BI_ItemQty]
AS
SELECT     dbo.IV00102.ITEMNMBR, dbo.IV00102.LOCNCODE, dbo.IV00102.QTYONHND, dbo.IV00102.ATYALLOC, dbo.IV00101.ITMTRKOP,
                      dbo.IV00102.QTYONHND - dbo.IV00102.ATYALLOC AS QtyAvlbl, dbo.IV00101.USCATVLS_2 AS Category, dbo.IV00101.CURRCOST,
                      dbo.IV00102.QTYONHND * dbo.IV00101.CURRCOST AS CostOnHand, dbo.IV00101.ITEMDESC,
                      CASE WHEN itmclscd LIKE '%fg%' THEN 'Finished Goods' ELSE 'Other' END AS FGOTH
FROM         dbo.IV00102 INNER JOIN
                      dbo.IV00101 ON dbo.IV00102.ITEMNMBR = dbo.IV00101.ITEMNMBR
WHERE     (dbo.IV00102.LOCNCODE > '') AND (dbo.IV00102.QTYONHND <> 0) AND (dbo.IV00101.ITMTRKOP = 1)

GO


No comments:

Post a Comment