在SQL存储过程中创建临时表
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在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.
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
以上是关于在SQL存储过程中创建临时表的主要内容,如果未能解决你的问题,请参考以下文章