ID     STATUS
    49      Y1
    49      Y2
    50      Y3
    49      Y4ID 49 相加得到 Y1Y2Y4怎么实现 谢谢!!

解决方案 »

  1.   

    ID     STATUS
        49      Y1
        49      Y2
        50      Y3
        49      Y4ID 49 相加得到 Y1Y2Y4-------------
    create funcion aa(@id int)
    returns varchar(100)
    as
    begin
    declare @s varchar(100)
    set @s=''
    select @s=@s+name from t where id=@id
    return @s
    endselect id,dbo.aa(id) from t
      

  2.   

    create table  t
    (ID id,    STATUS varchar(10))
    insert into t
    select     49,      'Y1' union all
    select     49,      'Y2' union all
    select     50,      'Y3' union all
    select     49,      'Y4'create function aa(@id int)
    returns varchar(100)
    as
    begin
    declare @s varchar(100)
    set @s=''
    select @s=@s+status from t where id=@id
    return @s
    endselect id,dbo.aa(id) from t group by idid                                                                                                               
    ----------- ---------------------------------------------------------------------------------------------------- 
    49          Y1Y2Y4
    50          Y3(2 row(s) affected)
      

  3.   

    不好意思,int型
    但我的確定義是id ,它被定義為int 型
      

  4.   

    create table  t
    (ID int,    STATUS varchar(10))
    insert into t
    select     49,      'Y1' union all
    select     49,      'Y2' union all
    select     50,      'Y3' union all
    select     49,      'Y4'create function aa(@id int)
    returns varchar(100)
    as
    begin
    declare @s varchar(100)
    set @s=''
    select @s=@s+isnull(status,'') from t where id=@id
    return @s
    endselect id,dbo.aa(id) from t group by idid                                                                                                               
    ----------- ---------------------------------------------------------------------------------------------------- 
    49          Y1Y2Y4
    50          Y3(2 row(s) affected)
      

  5.   

    把这个结果 Y1Y2Y4 保持到最后为49这行怎么处理  解决马上结贴