请教带表名参数的sql函数如何定义
1 回答
慕运维8079593
TA贡献1876条经验 获得超5个赞
create proc [dbo].[p_getParentPath]
@classid int output,
@tbTable nvarchar(20)
as
begin
declare @sql nvarchar(4000)
declare @re_str as varchar(100)
set @re_str = ''
select @re_str = ltrim(parentid) from s where classid = @classid
while exists (select 1 from s where classid = @classid and parentid <> 0)
begin
--如果直接写表名,没有问题
set @sql=' select '+@classid+' = b.classid , '+@re_str+'= ltrim(b.parentid) + '','' + '+@re_str+' from '+@tbTable+' a , '+@tbTable+' b where a.classid ='+@classid+' and a.parentid = b.classid'
exec (@sql)
end
end
- 1 回答
- 0 关注
- 548 浏览
添加回答
举报
0/150
提交
取消