I have a table like below where I iterate using a cursor to replace one value for another. Is there a way to do this using set operations in SQL?
In this example, I would replace the column with value 2525 with the value 255 and iterate through using a cursor.
company_name_id replacement_company_name_id
2525 255
11000201010737 10000701010293
12000301010533 12000301010532
Here's the code I am running:
declare @company_name_id bigint, @replacement_company_name_id bigint
declare company_name_cursor cursor for
select
company_name_id
, replacement_company_name_id
from #replacements
open company_name_cursor
fetch next from company_name_cursor into @company_name_id, @replacement_company_name_id
while @@FETCH_STATUS <> -1
begin
update user_job_during_school_job
set company_name_id = @replacement_company_name_id
where company_name_id = @company_name_id
fetch next from company_name_cursor into @company_name_id, @replacement_company_name_id
end
close company_name_cursor
deallocate company_name_cursor