34,593
社区成员
发帖
与我相关
我的任务
分享
--> 数据库版本:
--> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
--> 测试数据:[TB]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[TB]')
AND type in (N'U'))
DROP TABLE [TB]
GO
---->建表
create table [TB]([a] int,[b] int,[c] varchar(6))
insert [TB]
select 1,13,'诸葛亮' union all
select 2,8,'曹操' union all
select 3,16,'刘备' union all
select 4,9,'孙权' union all
select 5,13,'司马懿' union all
select 6,9,'关羽' union all
select 7,2,'张非'
GO
if object_id('tempdb.dbo.#TempRoomPriceTable') is not null
drop table tempdb.dbo.#TempRoomPriceTable
SELECT * into #TempRoomPriceTable FROM [TB];
exec ('select * from tempdb.dbo.#TempRoomPriceTable')
--> 查询结果
SELECT * FROM [TB]
--> 删除表格
--DROP TABLE [TB]
思路
先判断有没有该临时表么有的话就创建,有的话不做任何操作
当存储过程执行完毕会
自动删除临时表的
现创建#b
if object_id('#b') is not null drop table #b