I have a table (FORM) with a column like:
Serialno
424
536700045
345293885
424
466758884
424
424
244002678
My aim is to change duplicate rows of 424 to 424+(a unique 6 digit number) but the query below ended up changing all occurrence of 424 to 424748793.
i need to make the query generate a unique value for each row with a duplicate of 424 excluding the first 424.
Thanks.
declare @count int
declare @num varchar (9)
declare @id varchar (9)
dcelare @generic varchar(9)
set @id = RIGHT('000000' + CAST(ABS(CHECKSUM(NEWID())) % 999999 AS varchar(6)), 6)
set @num= '424'
set @generic = @id+@num
select @count= COUNT(serialno) from FORM
where serialno = '424'
while @count <> 1
begin
update FORM SET Serialno = @generic WHERE serialno = '424'
set @count = @count-1
end