/ Published in: SQL

A Temp table is great for combining multiple SELECT statements in a Sproc and outputting as just one table.
Don't forget to Drop the table after the SELECT * FROM #TempTableName at the end.
Don't forget to Drop the table after the SELECT * FROM #TempTableName at the end.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
CREATE TABLE #TableName( ID INT, FieldName nVarChar(30) ) INSERT INTO #TableName (ID, FieldName) SELECT ID, FieldName FROM dbo.TableName WHERE TYPE = 'Value' -- Do some stuff with the table DROP TABLE #TableName ------------------------------------------------------- FOR Multiple Queries repeat the INSERT INTO statement CREATE TABLE #TableName( ID INT, FieldName nVarChar(30) ) INSERT INTO #TableName (ID, FieldName) SELECT ID, FieldName FROM dbo.TableName WHERE TYPE = 'Value' INSERT INTO #TableName (ID, FieldName) SELECT ID, FieldName FROM dbo.TableName WHERE TYPE = 'Value' -- Do some stuff with the table eg SELECT * From #TableName DROP TABLE #TableName
Comments
