declare @uniqueid int;
declare @column2 nvarchar(100);
declare @last_column2 nvarchar(100);
declare @cnt int;
declare cur cursor for
select uniqueid, [col2]
from dbo.aTest
where [col1] = 'AA'
order by uniqueid
open cur
fetch next from cur into @uniqueid, @column2
set @last_column2 = ''
set @cnt = 0
while @@fetch_status = 0
begin
if @last_column2 = '' or (len(@column2)> 1 and @cnt > 1)
set @last_column2 = @column2
update a
set Col3Update = @last_column2
from dbo.aTest a
where uniqueid = @uniqueid
set @cnt = @cnt + 1
fetch next from cur into @uniqueid, @column2
end
close cur;
deallocate cur;
select * from dbo.aTest
order by uniqueid
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.