Here is a demonstration of the principle, you'll have to adapt it to your own table
create table #demo (test varchar(10), myValue varchar(10))
insert into #demo (test, myValue) values
('val1', 'value 1'),
('val1', 'value 1'),
('val2', 'value 1'),
('val2', 'value 2'),
('val2', 'value 2')
The query:
;with cte as
(
select test, myValue,
row_number() OVER (PARTITION BY test ORDER BY test, myValue) as rn
from #demo
)
select test, case when rn = 1 then myValue else null end as myValue
from cte
Comment:
Because of the partition on
ROW_NUMBER [
^] we are getting a row number for each row
within a
test
value. That is how you can detect the "duplicates".
Take care on how you choose to order the values as it will determine which are deemed to be duplicates.