Thursday, January 30, 2014

Dynamics GP - SQL to identify old items to be discontinued

--Use this to view the items that will be discontinued
select ITEMNMBR, ITEMDESC, itemtype from iv00101 where ITEMTYPE = 1
and ITEMNMBR in (select distinct itemnmbr from iv00102 where QTYONHND = 0 and QTYONORD = 0 and ATYALLOC = 0 and LOCNCODE = '')
and ITEMNMBR not in (select distinct itemnmbr from iv10201 where getdate()-DOCDATE <= 365)

--Use this to actually update the items and flag them as "Discontinued"
update iv00101 set itemtype = 2 where ITEMTYPE = 1
and ITEMNMBR in (select distinct itemnmbr from iv00102 where QTYONHND = 0 and QTYONORD = 0 and ATYALLOC = 0 and LOCNCODE = '')
and ITEMNMBR not in (select distinct itemnmbr from iv10201 where getdate()-DOCDATE <= 365)



--View to show all items with no activity in last 365 days
----------------------------------------------------------------
SELECT     dbo.IV00101.ITEMNMBR, dbo.IV00101.ITEMDESC, dbo.IV00101.ITEMTYPE, dbo.IV00101.ITMCLSCD, dbo.IV40400.ITMCLSDC
FROM         dbo.IV00101 INNER JOIN
                      dbo.IV40400 ON dbo.IV00101.ITMCLSCD = dbo.IV40400.ITMCLSCD
WHERE     (dbo.IV00101.ITEMTYPE = 1) AND (dbo.IV00101.ITEMNMBR NOT IN
                          (SELECT DISTINCT ITEMNMBR
                            FROM          dbo.IV10201 AS IV10201_1
                            WHERE      (GETDATE() - DOCDATE <= 365)))

No comments:

Post a Comment