How do I put this together correctly. I want to update the cost column with zero for the data that has row number greater than 1
update [dbo].[FlossbachWorkingDataloadFile]
set cost = 0
(
Select *,
ROW_NUMBER() over (Partition by [MasterIdentifier],[FundCode],[Cost] order by [MasterIdentifier],[FundCode],[Cost] ) as rowNumber
From [dbo].[FlossbachWorkingDataloadFile]
Where rowNumber > 1 )
FROM
(
Select *,
ROW_NUMBER() over (Partition by [MasterIdentifier],[FundCode],[Cost] order by [MasterIdentifier],[FundCode],[Cost] ) as rowNumber
From [dbo].[FlossbachWorkingDataloadFile]
Where rowNumber > 1) X
;WITH cte_delete AS (
Select *,
ROW_NUMBER() over (Partition by [MasterIdentifier],[FundCode],[Cost] order by [MasterIdentifier],[FundCode],[Cost] ) as rowNumber
From [dbo].[FlossbachWorkingDataloadFile]
)
DELETE FROM cte_delete
WHERE rowNumber > 1
I dont want to delete the records. I just want to update columns to 0 where there is more than 1 columns with the same masterid fundcode and cost value. can this be done with the rownumber