---------------------------------------------------
--类别-处理类别表中节点的路径
--2015.1.1
---------------------------------------------------
CREATE procedure [p_CategoryNodePath](@categoryId int)
as
 begin
    declare @parentNode int=0;
	if(@categoryId<1)--如果没有传入id,将获取最新的一个自增长编号
	begin
	  select @categoryId=MAX(CategoryID) from Category;
	end

    select @parentNode=ParentNode from Category where CategoryID=@categoryId;
	if(@parentNode<>0)
	begin
	  update Category set NodePath=(select (NodePath+'/'+convert(varchar,@categoryId)) as NewPath from Category where CategoryID=@parentNode) where CategoryID=@categoryId;
	end
	else
	begin
	  update Category set NodePath=@categoryId where CategoryID=@categoryId;--顶级目录
	end
  end

GO
