/* checks the age of an inventory dose not exceed x time */ use AlplaPROD_test1 DECLARE @timeCheck INT = [timeTest] select w.IdWarenLager as idWarehouse ,w.KurzBezeichnung as warehouse ,b.IdLagerAbteilung as locationId ,x.KurzBezeichnung as 'location' --,case when b.upd_date < Dateadd(minute, -(@timeCheck * 1.5), getdate()) then 'OVERDUE' else 'In-Progress' end as invStatus ,format(b.Upd_Date, 'M/d/yyyy HH:mm') as cycleCountStartAt ,b.Upd_User as blockedBy --,* from [dbo].[V_LagerAbteilungenInventuren] (nolock) as b -- get the loction name left join dbo.T_LagerAbteilungen (nolock) as x on x.IdLagerAbteilung = b.IdLagerAbteilung -- get the whse left join dbo.T_WarenLager (nolock) as w on x.idWarenLager = w.idWarenLager where status = 1 and b.Upd_Date < Dateadd(minute, -@timeCheck, getdate())