I just did a new test using a cursor this time.
CREATE table #regions (
ipFloat float null,
countryId int null)
insert into #regions (ipFloat) select distinct top 500 ipFloat from tbl_logs
declare @i float, @id int
DECLARE cSE CURSOR READ_ONLY
FOR select ipFLoat from #regions
OPEN cSE
FETCH NEXT FROM cSE INTO @i
WHILE @@FETCH_STATUS = 0
BEGIN
select @id = countryId from tbl_ip2countries where @i between ipFrom and ipTo
update #regions set countryId = @id where ipFloat = @i
FETCH NEXT FROM cSE INTO @i
END
CLOSE cSE
DEALLOCATE cSE
select * from #regions
drop table #regions
The results are quite surprising! For 100 ips, it took only 6 seconds instead of minutes.
But I'm sure there's a way to get this done quickly whitout using a cursor. I just can't find it out.
Thanks for any idea,
Stephane