copchilul meu de azi, primul meu cursor:
-- select * from
app.Applications_old
declare @comp int
declare @id_old int
declare @id_new int
declare @a varchar (100)
declare @b varchar (100)
DECLARE c CURSOR FOR SELECT id_apps FROM
app.applications_old where
id_apps_new is null;
SET
@id_new = 2;
OPEN c;
FETCH next from c into @id_old;
WHILE @@FETCH_STATUS = 0
begin
/* aflu daca numele aplicatiei e diferit de precedentul */
select @a = name from app.Applications_old where
ID_Apps = @id_old -1
select @b = name from app.Applications_old
where ID_Apps =
@id_old;
if @a=@b set @comp = 0
else set @comp = 1;
--/* fac update in
tabela*/
if @comp = 0 update app.Applications_old
set
ID_Apps_new = @id_new --
pastrez id pentru nume neschimbat
where ID_Apps =
@id_old
else set @id_new = @id_new
+ 1; -- cresc id pentru nume schimbat
update app.Applications_old
set
ID_Apps_new = @id_new
where
ID_Apps = @id_old;
-- update pentru nume schimbat
-- set @id_old =
@id_old+1;
-- select @a 'a', @b 'b', @comp 'comparare', @id_new 'id
new', @id_old 'id old'
print @id_old
print @b print
@comp print @id_new
fetch c into @id_old
end
CLOSE c;
deallocate c
Niciun comentariu:
Trimiteți un comentariu
spui, semnezi.