• Hugo Kornelis (11/18/2010)


    Good question; many people would expect this to work. (As I did, the first time I ran into this. And the second, third, ... - I answered correctly but only because I've run into this often enough to cause a permanent dent in my forehead).

    I can only echo Hugo's comment about why I immediately knew the answer before seeing the available multiple choice options: miserable first-hand experience.

    In my case, though, "third" would be followed by "nth", where n was an embarrassingly large integer. :hehe:

    The not-quite-truthful error-message returned in SSMS, "There is already an object named '#MyNonexistentTempTable' in the database.", had me trying to DROP a non-existent table, with, of course, an unproductive outcome.

    My take-home lesson on this is that T-SQL doesn't really like even the few elements of procedural code provided to us (couldn't we please have ELSEIF???) The compiler pretty much ignores the fact that the 2 SELECT..INTO statements are mutually exclusive executions.

    Good question!

    Rich