Creating a Temp Table on the Fly

Posted on Updated on

Sometimes we need to create a temporary table on the fly to hold our data for whatever reasons. Here is one approach in creating a temporary table on the fly.

–LOCAL SCOPE
–ONLY YOU CAN SEE THIS TEMP TABLE

SELECT *
INTO #forMe
FROM Customer

SELECT * FROM #forMe

–GLOBAL SCOPE
–EVERYONE CAN SEE THIS TEMP TABLE

SELECT *
INTO ##forEveryone
FROM Customer

SELECT * FROM ##forEveryone

DROP TABLE #forMe
DROP TABLE ##forEveryone

Advertisements