我写的一个存储过程建立动态临时库并调用
CREATE PROC order_unsub_search
@tablename nvarchar(100)
AS
BEGIN
declare @createtable nvarchar(500) --建立动态临时库
set @createtable='select * into '+ rtrim(@tablename)+' from c_order_detail '
exec(@createtable)
declare @usertable nvarchar(1000) --调用临时库
set @usertable='select * from '+ rtrim(@tablename)
exec(@usertable)
END
GO
------解决方案--------------------SQL code
.
.
.
as
begin
--得提前判断这个表存不存在,存在就必须删了
if object_id(@tablename) is not null
exec('drop table '+@tablename)
.
.
.
end