You can't use object_id() to determine if you need to create the #tmp
table, because if you do that, it doesn't necessarily exist to the compiler
while trying to define a cursor over the #tmp table, so the install/compile
of the TransactSQL fails.