• HanShi mentioned local and global temp tables. You don't see this as often but a global temp table has two numbers signs in front of it like so: ##temptable.

    To get some understanding about the difference between the two, open a new query window in SSMS and run these SELECT statements:

    CREATE TABLE #LocalTempTable(xId int);--(1) Local Temp Table

    CREATE TABLE ##GlobalTempTable(xId int);--(2) Global Temp Table

    INSERT INTO #LocalTempTableVALUES(1);

    INSERT INTO ##GlobalTempTableVALUES(1);

    Then, in the same query window, you could successfully run these queries:

    SELECT * FROM ##GlobalTempTable

    SELECT * FROM #LocalTempTable

    If you open a new query window, however, and run the two SELECT statements above, the first will be successful but the second one will fail.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001