/** This will be replacing activeArticles once all data is remapped into this query. make a note in the docs this activeArticles will go stale sooner or later. **/ use [test1_AlplaPROD2.0_Read] select a.Id, a.HumanReadableId as av, a.Alias as alias, p.LoadingUnitsPerTruck as loadingUnitsPerTruck, p.LoadingUnitsPerTruck * p.LoadingUnitPieces as qtyPerTruck, p.LoadingUnitPieces, case when i.MinQuantity IS NOT NULL then round(cast(i.MinQuantity as float), 2) else 0 end as min, case when i.MaxQuantity IS NOT NULL then round(cast(i.MaxQuantity as float),2) else 0 end as max from masterData.Article (nolock) as a /* sales price */ left join (select * from (select id, PackagingId, ArticleId, DefaultCustomer, ROW_NUMBER() OVER (PARTITION BY ArticleId ORDER BY ValidAfter DESC) AS RowNum from masterData.SalesPrice (nolock) where DefaultCustomer = 1) as x where RowNum = 1 ) as s on a.id = s.ArticleId /* pkg instructions */ left join masterData.PackagingInstruction (nolock) as p on s.PackagingId = p.id /* stock limits */ left join masterData.StockLimit (nolock) as i on a.id = i.ArticleId where a.active = 1 and a.HumanReadableId in ([articles])