Regarding the temptable: I use the @toggle flag to determine if the temptable is already created or not.
In the first loop, @toggle=0 and a "select into" is used to create the table. @toggle is also set to 1
In the next loops, @toggle=1, resulting in an "insert into"
If you want to be sure this table doesn't exist, add this code before the cursor declaration:
begin try
drop table #db03632
end try
begin catch
-- dummy
end catch
Regarding the "Strange characters": that's a result of different charactersets :crazy: . As suggested, copy code into an editor and remove the goofy characters
Wilfred
The best things in life are the simple things