A temporarily solution could following code change be:
select @cnt = count(*) from #a, fh where
...
if @cnt between 1 and 4
begin
set @SQLCacheProblem = '1'
set rowcount 1
end
while @cnt > 0
begin
update fh set
...
select @dbc=@@RowCount, @dbe=@@Error
if @dbe<>0
begin
...
return
end
if @SQLCacheProblem <> '1'
set @cnt = 0
else
set @cnt = @cnt - @dbc
end
if @SQLCacheProblem = '1'
begin
set @SQLCacheProblem = '0'
set rowcount 0
end
Max 3 extra updates cost much less than the "forced recompile".
Leif Haraldsson