I can't get results to group the id together after I put in the case statement
,case when fs.ITEMID like '%ME' then left(fs.[ITEMID],4) -- case 1
ELSE fs.ITEMID
End as 'SKU'
SELECT
ROW_NUMBER() over(order by fs.[ITEMID] asc) as 'Row_ID',
--fs.[ITEMID] as 'SKU',
Convert(varchar(10),CONVERT(date,fs.[STARTDATE],101),101) as 'Date'
,case when fs.ITEMID like '%ME' then left(fs.[ITEMID],4) -- case 1
ELSE fs.ITEMID
End as 'SKU'
,CASE fs.[FORECASTSALESGROUPIDASL]--case2
WHEN 'CANA' THEN 'US' ELSE fs.[FORECASTSALESGROUPIDASL]
END AS 'FSG'
, fs.[FORECASTCUSTGROUPIDASL] as 'FCG'
,SUM(fs.[SALESQTY]) AS 'QTY'
FROM [PCIS_AX2009_BEN].[dbo].[FORECASTSALES] fs
JOIN [PCIS_AX2009_BEN].[dbo].[INVENTTABLE] it
ON fs.[ITEMID] = it.[ITEMID] and fs.[DATAAREAID] = it.[DATAAREAID]
WHERE fs.[DATAAREAID] = 'BCUS'
AND fs.[MODELID] IN ('DH_MANUAL','DH_BASE')
-- AND fs.[STARTDATE] >= DATEADD(mm, DATEDIFF(m,0,GETDATE())- 1,0)
AND fs.[STARTDATE] >= '2017-01-01'
AND fs.[ITEMGROUPID] IN ('100','101','103','202', '203')
AND fs.[FORECASTITEMGROUPIDASL] NOT IN ('CL1T','None','Discon','')
AND it.[PCISCMITEMSTATUSCLASSIFID] NOT IN ('Discontinued','')
AND fs.[FORECASTSALESGROUPIDASL] Not In('7PA','7PC','P_MEXI','P_MIDE','7PT','QVC','7PH','7PK','P_RUS','P_TRI','SDCX','P_URB','URB')
GROUP BY fs.[ITEMID]
,fs.[STARTDATE]
,CASE fs.[FORECASTSALESGROUPIDASL]
WHEN 'CANA' THEN 'US' ELSE fs.[FORECASTSALESGROUPIDASL]
END
,fs.[FORECASTCUSTGROUPIDASL]