对SQL2005不太熟,请各位帮帮忙. 本人是想在此存储过程中实现不同的用户调用时产生不同的数据表,这样好跟踪等等. if object_id('mytemp') is not null drop table mytemp select * into mytemp from ddtt
exec ' drop table '+ @mytemp
谢谢, select * into mytemp from ddtt 又怎改?
if object_id('mytemp') is not null 这里的表名呢?
if object_id(@TableName) is not null
EXEC 'select * into mytemp from '+@mytemp
用exec来执行一个sql的字串 EXEC 'select * from '+@mytemp
create proc p1(@tableName nvarchar(128)) as begin declare @cmd nvarchar(4000); if object_id(@TableName) is not null begin set @cmd = ' drop table '+@tableName; exec (@cmd); endset @cmd = 'select * into '+@tableName + ' from 数据表'; exec (@cmd); end
本人是想在此存储过程中实现不同的用户调用时产生不同的数据表,这样好跟踪等等.
if object_id('mytemp') is not null
drop table mytemp
select * into mytemp from ddtt
谢谢,
select * into mytemp from ddtt
又怎改?
if object_id(@TableName) is not null
EXEC 'select * from '+@mytemp
create proc p1(@tableName nvarchar(128)) as
begin
declare @cmd nvarchar(4000); if object_id(@TableName) is not null
begin
set @cmd = ' drop table '+@tableName;
exec (@cmd);
endset @cmd = 'select * into '+@tableName + ' from 数据表';
exec (@cmd);
end