database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
ㆍMS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MS-SQL Q&A 3740 게시물 읽기
No. 3740
카테고리 질문입니다.
작성자
이경훈
작성일
2007-09-11 04:53
조회수
2,157

안녕하세요...



무한 카테고리에 관하여 검색중에 다음과 같은 글을 발견했습니다.



--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



몰라서 질문드립니다... ㅠ.ㅠ 답변주시면 넘 감사드립니다.



[Top]
No.
제목
작성자
작성일
조회
3743카테고리에 관하여 [1]
구름이
2007-09-11
2432
3742nvarchar 타입의 숫자 정렬
MS$
2007-09-11
2449
3741random 으로 데이타를 가져올 수 있나요?.. [1]
sql초보
2007-09-11
2566
3740카테고리 질문입니다.
이경훈
2007-09-11
2157
3739정말 기초적인 질문 하나 드립니다 [1]
corea21
2007-09-10
2308
3738교착상태
김지은
2007-09-10
2637
3736db connecting 이 실행 중 끊어집니다. ㅠ;;
이덕희
2007-09-07
2183
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.016초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다