WITH mapping AS (
SELECT ROW_NUMBER() OVER (ORDER BY dbo.Shipping.id)
ROW_NUM, dbo.Shipping.PartNum, dbo.Shipping.id,dbo.masterdata.id as Masterdata_id,
dbo.MasterData.Material, dbo.MasterData.SOrg, dbo.MasterData.DChl, dbo.MasterData.DV,
dbo.MasterData.Plant, dbo.MasterData.Shipto, dbo.Shipping.MessageReleaseNum,
dbo.Shipping.MessageReleaseDate, dbo.Shipping.ShipToGSDBCode, dbo.Shipping.PurchaseOrderNum,
dbo.Shipping.DockCode, dbo.Shipping.ReserveLineFeed, dbo.Shipping.LineFeed, dbo.Shipping.LastShippedQty,
dbo.Shipping.LastShippedDate, dbo.Shipping.CumShippedQty, dbo.Shipping.ForecastTime
FROM dbo.Shipping inner join dbo.shippingfile on dbo.Shipping.excelfile = dbo.shippingfile.id
left join dbo.masterdata on dbo.Shipping.PartNum = dbo.masterdata.CustomerMaterialNumber
where ForecastDate = FORMAT(GETDATE(),'yyyyMMdd', 'en-us') )
SELECT (CASE WHEN PartNum=(SELECT PartNum FROM mapping TBLSUB WHERE TBLSUB.ROW_NUM+1=mapping.ROW_NUM )
THEN ' ' ELSE PartNum END) PartNum,id,Masterdata_id,Material,SOrg,DChl, DV,Plant, Shipto,MessageReleaseNum,
MessageReleaseDate,ShipToGSDBCode,PurchaseOrderNum, DockCode, ReserveLineFeed, LineFeed, LastShippedQty,
LastShippedDate, CumShippedQty, ForecastTime FROM mapping