这个需要写一个函数来做。
CREATE FUNCTION [dbo].[fget_route]
(
@cId VARCHAR(10),
@croute VARCHAR(8000)
)
RETURNS varchar(8000)
AS
BEGIN
DECLARE @uproute VARCHAR(1000)
DECLARE @up_Id VARCHAR(10)
IF @cId <> '0' AND @cId <> '' BEGIN
--取到上级ID
SELECT @up_Id = up_Id FROM [532信息] WHERE id = @cId
--取上级route
SELECT @uproute = [route] FROM [532信息] WHERE id = @up_Id
IF @croute <> '' BEGIN
SET @croute = @cId+','+@uproute+ ',' +@croute
END
ELSE BEGIN
SET @croute = @cId+','+@uproute
END
RETURN dbo.fget_route(@up_Id,@croute)
END
RETURN @Allroute
END
--版权所有:532信息网