慕运维8079593
create proc [dbo].[p_getParentPath]@classid int output,@tbTable nvarchar(20)asbegindeclare @sql nvarchar(4000)declare @re_str as varchar(100)set @re_str = ''select @re_str = ltrim(parentid) from s where classid = @classidwhile 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)endend