Monday, March 19, 2012

Got err: There is already an object named '#TEMP' in the datab

Thank you for the reply. I did figured it out last Friday after I keep
messing with it. I have a if -else code where the if xxx then insert yyy to
#temp else insert zzz to #temp. I didn't know SQL doesn't allow #temp to be
used in this fashion which is usually allowed in development coding. I
changed the else to insert to #temp2 and it worked.
Thanks, Alpha
"Aaron Bertrand [SQL Server MVP]" wrote:

> Maybe you could show your code...
>
> "Alpha" <Alpha@.discussions.microsoft.com> wrote in message
> news:0F8B1D0C-6CD7-42D5-BE0E-4D473E39C188@.microsoft.com...
>
>> #temp else insert zzz to #temp. I didn't know SQL doesn't allow #temp to
> be
> used in this fashion which is usually allowed in development coding.
Well, it doesn't actually EXECUTE the code, so it doesn't understand that
your IF/ELSE can only result in one path. It merely sees you trying to
create the same #temp table twice...|||I see. Thank you for your help.
"Aaron Bertrand [SQL Server MVP]" wrote:

> Well, it doesn't actually EXECUTE the code, so it doesn't understand that
> your IF/ELSE can only result in one path. It merely sees you trying to
> create the same #temp table twice...
>
>

No comments:

Post a Comment