looking on the update statement
update #TempTotalTable
set NoOfCol = NoOfCol
from #ColumnPerTable
where #TempTotalTable.TBName = #ColumnPerTable.TBName
you might want to prefix the NoOfCol with #ColumnPerTable, i think you are setting the column with its...