比如你从小分类表里(small)查出来的declare @smallid varchar(10),@count int
set @count=1
set @smallid=''
while @count<=(select count(*) from small)
begin
set @smallid=@smallid+','+(select id from small where id=@count)     --这里的id是你表里标识列的自增值
set @count=@count+1
end
select right(@smallid,len(@smallid)-1)结果的小分类ID是15,16,17,18,19,20

解决方案 »

  1.   

    declare @smallid varchar(10),@count int
    set @count=1
    set @smallid=''
    while @count<=(select count(*) from small)
    begin
    set @smallid=@smallid+','+(select id from small where id=@count)     --这里的id是你表里标识列的自增值
    set @count=@count+1
    end
    select right(@smallid,len(@smallid)-1)
    这个好像行不能啊
    我的代码如下:
      

  2.   

    ALTER PROCEDURE [dbo].[Select_IndexNews]
    @ListInfo_CatagroyID int
    AS

    declare @smallid varchar(10),@count int
    set @count=1
    set @smallid=''
    while @count<=(select count(*) from News_Catagroy where Catagroy_ParentID=@ListInfo_CatagroyID)
    begin
    set @smallid=@smallid+','+convert(varchar,(select Catagroy_ID from News_Catagroy where Catagroy_ParentID=@count))
    set @count=@count+1
    end
    print @smallid