怎样用表名作为自定义函数的参数(要求函数中向变量表插入自来参数表数据)

YiOnLine 2005-05-11 12:55:17
--想这样写.但不能执行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

请教了.
...全文
91 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jjlook 2005-05-11
  • 打赏
  • 举报
回复
自定义函数中不能用execute的,
xluzhong 2005-05-11
  • 打赏
  • 举报
回复
把它改为存储过程/

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧