逆向查询所有父栏目
1
CREATE PROCEDURE c_GetAllContentByChid
2
@Chid varchar(50)
3
AS
4
declare @str varchar(4000)
5
set @str=','+@Chid
6
while @@ROWCOUNT>0
7
8
select @str=@str+','+cast(ParentID as varchar(50)) from Tbl_ChannelInfo
9
where charindex(','+cast(Cid as varchar(50))+',',@str+',')>0
10
and charindex(','+cast(ParentID as varchar(50))+',',@str+',')=0
11
12
select a.ChannelTitle,b.* from Tbl_ContentInfo as b
13
inner join
14
(select * from Tbl_ChannelInfo where charindex(',{'+cast(Cid as varchar(50))+'},',@str+',')>0 ) as a
15
on b.ParentID=a.cid
16
GO

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16
