1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| open CURS_TMP
fetch next from CURS_TMP into @id, @p, @1, @2, @3, @4, @5, @6, @7, @8, @9
while @@fetch_status = 0
begin
if isnull(charindex(';', @1), 0) <> 0
begin
set @ideb = 0
set @ifin = 0
while (@ifin < len(@1))
begin
set @ideb = @ifin
set @ifin = charindex(';', @1, (@ideb+1))
if @ifin<>1 and @ifin<>len(@1)
begin
insert into TABLE_1 (COL_1, COL_2, COL_3) values (@id, substring(@1,(@ideb+1),(@ifin-@ideb-1)), 23)
end
end
end
if isnull(charindex(';', @2), 0) <> 0
begin
set @ideb = 0
set @ifin = 0
while (@ifin < len(@2))
begin
set @ideb = @ifin
set @ifin = charindex(';', @2, (@ideb+1))
if @ifin<>1 and @ifin<>len(@2)
begin
if (select count(COL_2) from TABLE_1 where COL_1 = @id and COL_2 = @2) = 0
insert into TABLE_1 (COL_1, COL_2, COL_3) values (@id, substring(@2,(@ideb+1),(@ifin-@ideb-1)), 19)
else
update TABLE_1 set COL_3 = (COL_3*19) where COL_1 = @id and COL_2 = @2
end
end
end
fetch next from CURS_TMP into @id, @p, @1, @2, @3, @4, @5, @6, @7, @8, @9
end
close CURS_TMP
deallocate CURS_TMP |
Partager