代码如下:
declare @test varchar(max)
set @test=''
IF EXISTS(SELECT iid FROM sort WHERE Parent=0)
begin
select @test=@test+','+CAST(iid AS VARCHAR) from sort WHERE Parent=0 ORDER BY iid
IF(LEN(@test)>0)
begin
SET @test=RIGHT(@test,LEN(@test)-1)
END
END
select @test