Home Forums SQL Server 2005 T-SQL (SS2K5) Temp Table Name confusion with Nested Procedures? RE: Temp Table Name confusion with Nested Procedures?

  • WayneS (7/5/2011)


    mtillman-921105 (7/1/2011)


    OK, now I wish that I could borrow the head-desk avatar from WayneS! :angry:

    Feel free to borrow it anytime... it's at http://www.dreamwidth.org/userpic/21008/20791

    (Sometimes, I'd like to change my avatar to this one - but I think Steve would ask me to change it.)

    [evil grin]Hmm... isn't Steve on vacation right now?[/evil grin]

    Anyway, to answer your question: From BOL:CREATE TABLE

    A local temporary table created within a stored procedure or trigger can have the same name as a temporary table that was created before the stored procedure or trigger is called. However, if a query references a temporary table and two temporary tables with the same name exist at that time, it is not defined which table the query is resolved against.

    (emphasis mine)

    Thank you Wayne! That explains it. It's a mystery to my why this hasn't happened to me more frequently. But I've learned my lesson and at least there's an explanation.

    Hilarious .gif by the way. I'll have to share that one.

    The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking