Create procedure prGetList
@chnList nvarchar(2000) output
as
Set @chnList=''
select @chnList = @chnList+Rtrim(ID)+',' from A 
Select @chnList=Left(@chnList,Len(@chnList)-1)
go

解决方案 »

  1.   

    --建立测试环境
    Create table A(ID Int)
    --插入数据
    Insert A Select 1
    Union Select 2
    Union Select 3
    Union Select 4
    Union Select 5
    Union Select 6
    Union Select 7
    Union Select 8
    Union Select 9
    Union Select 10
    GO
    --建立存储过程
    Create procedure prGetList
    @chnList nvarchar(2000) output
    as
    Set @chnList=''
    select @chnList = @chnList+Rtrim(ID)+',' from A 
    Select @chnList=Left(@chnList,Len(@chnList)-1)
    go
    --测试
    Declare @chnList nvarchar(2000)
    EXEC prGetList @chnList output
    Select @chnList
    GO
    --删除测试环境
    Drop table A
    Drop procedure prGetList
    GO
    --结果
    /*
    1,2,3,4,5,6,7,8,9,10
    */
      

  2.   

    Create procedure prGetList
    @chnList nvarchar(2000) output
    as
    Set @chnList=''
    select @chnList = @chnList+Rtrim(ID)+',' from A 
    Select @chnList=Left(@chnList,Len(@chnList)-1)
      

  3.   

    看来还是csdn上的牛人多啊!! 有星星的就是不一样,
    我在大富翁上问了一天都没有人知道-------------------------------------
    另外怎么结帖啊?????