Execute these queries using Excel Query Builder |
/* Products not used on any booking*/
select m.product_code as [Inventory Code],
m.descriptionV6 as [Description],
isnull(i.product_code_v42,'') as [Item Code],
isnull(i.booking_no_v32,'') as [Last Booking #],
isnull(i.Comment_desc_v42,'') as [Description],
isnull(i.FirstDate,'') as [Not used on booking since]
from tblinvmas m
LEFT JOIN vwItemAndHist I on I.product_code_v42 = m.product_code
Where I.product_code_v42 IS NULL
/* Products not placed on any booking in X Months - uses reservation date of gear*/
DECLARE @Months AS INT
SET @Months = 12
SELECT m.product_code AS [Inventory Code],
m.descriptionv6 AS [Description]
FROM tblinvmas m
WHERE m.product_code NOT IN (SELECT DISTINCT product_code FROM vwitemandhist
WHERE m.product_code = product_code_v42
AND Datediff(month, firstdate, Getdate()) <= @Months)
ORDER BY m.product_code