1CREATE PROCEDURE c_GetAllContentByChid
2@Chid varchar(50)
3 AS
4declare @str varchar(4000)
5set @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
12select a.ChannelTitle,b.* from Tbl_ContentInfo as b
13inner join
14(select * from Tbl_ChannelInfo where charindex(',{'+cast(Cid as varchar(50))+'},',@str+',')>0 ) as a
15on b.ParentID=a.cid
16GO
2@Chid varchar(50)
3 AS
4declare @str varchar(4000)
5set @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
12select a.ChannelTitle,b.* from Tbl_ContentInfo as b
13inner join
14(select * from Tbl_ChannelInfo where charindex(',{'+cast(Cid as varchar(50))+'},',@str+',')>0 ) as a
15on b.ParentID=a.cid
16GO