怎样用表名作为自定义函数的参数(要求函数中向变量表插入自来参数表数据)
--想这样写.但不能执行EXEC.
CREATE function f_desy(@atable varchar(20))
returns @re table(id int,iid int,ipid int,name varchar(200))
as
begin
declare @temp table(iid int identity(0,1),id int,pid int,name varchar(200))
declare @sql varchar(200)
set @sql='insert into @temp(id,pid,name) select id,pid,name from '+@atable
exec(@sql)
insert into @re
select id,iid,ipid=(select iid from @temp a where a.id=b.pid),name from @temp b
return
end
go
请教了.