Hi @Joaquim Costa ,
If the ACTIVE column means the row is useful. I think the value of ACTIVE column for not repeated data need also to be 1. So, please try below T-SQL.
-----create table
create table dbo.test( id int, CAR varchar(30), ACTIVE int)
insert into dbo.test(id, CAR, ACTIVE)
values
(1, 'AAA-25-35', 0),
(2, 'LDB-25-35', 0),
(3, 'LDB-00-35', 0),
(4, 'LDB-25-35', 0),
(5, 'LDB-00-35', 0),
(6, 'LDC-10-10', 0),
(7, 'LDC-10-10', 0),
(8, 'LDB-00-35', 0)
select * from dbo.test
----update table
WITH CTE AS
(
SELECT
row_number() over (partition by CAR order by id) as t
, CAR , ACTIVE
FROM dbo.test
)
update CTE
SET ACTIVE = 1
WHERE t=1
select * from dbo.test
-----drop table
drop table if exists dbo.test
Best regards,
Cathy
If the response is helpful, please click "Accept Answer" and upvote it, thank you.
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.