Thanks from me too.
Just a little remark:
SELECT COUNT(*) - 1 INTO VarCount FROM Table1;
is better with "- 1", because if not, the last row is FETCH-ed twice/ two times.
I was implementing a simialr thing kindly let me know, why the last row is fetched twice?