I am currently rebuilding an SSRS report that was external to D365 and hosted in SQL Server Reporting Services.
I want to know the best way of translating the SQL logic below to build a query in X++
****** SQL Logic ******
select a.WareHouseID, a.itemid, a.[Description],a.jbgmaingroup
, COUNT(case when a.DaysToExpiration >= 0 AND a.DaysToExpiration <= 5 then 1 end) as [0 to 5 cases]
, COUNT(case when a.DaysToExpiration >= 6 AND a.DaysToExpiration <= 10 then 1 end) as [6 to 10 cases]
, COUNT(case when a.DaysToExpiration >= 11 AND a.DaysToExpiration <= 16 then 1 end) as [11 to 16 cases]
, COUNT(case when a.DaysToExpiration >= 17 AND a.DaysToExpiration <= 20 then 1 end) as [17 to 20 cases]
, COUNT(case when a.DaysToExpiration >= 21 AND a.DaysToExpiration <= 30 then 1 end) as [21 to 30 cases]
, COUNT(case when a.DaysToExpiration >= 31 then 1 end) as [31 and over cases]
, SUM(case when a.DaysToExpiration >= 0 AND a.DaysToExpiration <= 5 then [Weight] end) as [0 to 5 Kgs]
, SUM(case when a.DaysToExpiration >= 6 AND a.DaysToExpiration <= 10 then [Weight] end) as [6 to 10 Kgs]
, SUM(case when a.DaysToExpiration >= 11 AND a.DaysToExpiration <= 16 then [Weight] end) as [11 to 16 Kgs]
, SUM(case when a.DaysToExpiration >= 17 AND a.DaysToExpiration <= 20 then [Weight] end) as [17 to 20 Kgs]
, SUM(case when a.DaysToExpiration >= 21 AND a.DaysToExpiration <= 30 then [Weight] end) as [21 to 30 Kgs]
, sum(case when a.DaysToExpiration >= 31 then [Weight] end) as [31 and over Kgs]
FROM (
SELECT dbo.Inventory.WareHouseID, dbo.Inventory.ItemID, it.ItemName as [Description], it.jbgmaingroup, dbo.Inventory.Weight,
DATEDIFF(DD, convert(date, getdate()),dbo.Inventory.ExpirationDate) as DaysToExpiration
FROM dbo.Inventory
inner join [edc-clst07sql01].[AX_50_Prod].[dbo].[INVENTTABLE] it on dbo.Inventory.itemid = it.itemid
WHERE (RIGHT(LEFT(dbo.Inventory.SerialID, 14), 3) NOT LIKE ‘%[^0-9]%’) AND (RIGHT(LEFT(dbo.Inventory.SerialID, 11), 1) NOT LIKE ‘%[^0-9]%’)
AND (dbo.Inventory.SerialID LIKE ‘___[0-9][0-9][0-9][0-9][0-9][0-9][A-Z][0-9][0-9][0-9][0-9][0-9]%’)
AND dbo.Inventory.itemid in (@itemID) AND dbo.Inventory.warehouseid = @warehouseID
AND it.dataareaid = ‘bdc’) a
group by a.WareHouseID, a.itemid, a.[Description], a.jbgmaingroup
order by a.itemid, a.WareHouseID, a.jbgmaingroup
Do you have any ideas on how to translate the SQL expression “case when a.DaysToExpiration >= 0 AND a.DaysToExpiration <= 5 then 1 end) as [0 to 5 cases]” in X++
Note: Screenshot below.