안녕하세요...
무한 카테고리에 관하여 검색중에 다음과 같은 글을 발견했습니다.
--table 생성
Create TABLE [tbmCate] (
[CateID] [int] NOT NULL ,
[CateName] [varchar] (50) ,
[Depth] [tinyint] NULL ,
[DisplaySeq] [smallint] NULL ,
[ParentID] [int] NULL ,
) ON [PRIMARY]
GO
--test data 생성(키,분류명,깊이,진열순서,부모키값)
Insert Into tbmCate (CateID,CateName,Depth,DisplaySeq,ParentID) Values (1,'컴퓨터/주변기기',1,1,0);
Insert Into tbmCate(CateID,CateName,Depth,DisplaySeq,ParentID) Values (2,'데스크탑',2,1,1);
Insert Into tbmCate(CateID,CateName,Depth,DisplaySeq,ParentID) Values (3,'삼성',3,1,2);
Insert Into tbmCate(CateID,CateName,Depth,DisplaySeq,ParentID) Values (4,'삼성패키지',4,1,3);
Insert Into tbmCate(CateID,CateName,Depth,DisplaySeq,ParentID) Values (5,'팬티엄4',5,1,4);
Insert Into tbmCate(CateID,CateName,Depth,DisplaySeq,ParentID) Values (6,'가전',1,1,0);
Insert Into tbmCate(CateID,CateName,Depth,DisplaySeq,ParentID) Values (7,'샐러론',6,1,5);
/*
프로시저 생성
Create Proc up_tbmCate_SelectByFullPath
@CateID int
AS
Begin
Declare @strRetCateName varchar(50) , @strRetValue varchar(600)
Declare @intParent int , @intDepth int
Set @strRetValue =''
Select @intDepth=Depth,@strRetCateName=CateName,@intParent=ParentID From tbmCate Where
CateID=@CateID
Set @strRetValue= @strRetCateName
WHILE @intDepth > 1
BEGIN
Set @intDepth=@intDepth-1
begin
Select @strRetCateName=CateName,@intParent=ParentID,@intDepth=Depth From tbmCate
Where CateID=@intParent
Set @strRetValue=@strRetCateName + ' > '+@strRetValue
end
END
Select @strRetValue
End
--full 경로 반환
Exec up_tbmCate_SelectByFullPath 5
-- 컴퓨터/주변기기 > 데스크탑 > 삼성 > 삼성패키지 > 팬티엄4
제가 궁금한건 위 프로시져는 자신의 카테고리에 해당하는 부모 카테고리 정보를 나열한것인데
그렇다면 자신의 하위 카테고리를 나타나게 하려면 프로시져를 어떻게 작성을 해야 하는지요..
예를들어 "데스크탑"을 클릭시 다음과 같은 결과가 나오면 됩니다.
데스크탑 > 삼성 > 삼성패키지 > 팬티엄4
몰라서 질문드립니다... ㅠ.ㅠ 답변주시면 넘 감사드립니다.
|