Hi @Sumit ,
Please also check another method:
;with cte as
(select *,row_number() over(partition by TCode,Fcode,PCode,TpCode,CCode,CityCode,ACode,ICode order by TCode) rn
from #Dup)
,cte2 as
(select *,max(rn) over(partition by TCode,Fcode,PCode,TpCode,CCode,CityCode,ACode,ICode order by TCode) mm
from cte )
select TCode, Fcode, PCode, TpCode, CCode, CityCode, ACode, ICode,
case when rn=1 then 'Original'
when mm=2 then 'Duplicate'
else concat('Duplicate-', rn-1) end Result
from cte2
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.