请教一个题  求助
     表 A
   ------------------
    id         CS
  --------------------
     1         我
  --------------------
     2         是
  --------------------
     3         一
  -------------------
     4         名
---------------------
    5        学生      
输出一行结果为:
 我是一名学生
--------------------------
(不要用游标的 游标的懂了)

解决方案 »

  1.   

    select group_concat(CS ORDER BY id) from A;
      

  2.   

    我用的是SQL2005  好像没有这个函数样
      

  3.   

    mysql写法:
    SELECT GROUP_CONCAT(CS) FROM tb
    sql server就是行专列
      

  4.   

    select (select CS + '' from tmp for xml path('')),这是SQL Server 2005下的实现.
      

  5.   

    sqlserver没有这样的函数 要自己写一个类似的函数
      

  6.   

    这个函数在 MySQL 4.1 中被加入。
      

  7.   

    select CS=stuff((select CS+'' from tb for xml path(''),1,1,'') from tb
      

  8.   

    declare @tb table(name nvarchar(50))insert into @tb 
    select 'Wo' union all
    select 'Shi' union all
    select 'Yi' union all
    select 'Ming' union all
    select 'Xue' union all
    select 'Sheng'declare @str nvarchar(500);
    set @str='';select @str=@str+name+'+' from @tb;
    select Left(@str,len(@str)-1);
      

  9.   


    declare @表A table(id int,CS nvarchar(5))
    insert into @表A
    select 1,'我' union all
    select 2,'是' union all
    select 3,'一' union all
    select 4,'名' union all
    select 5,'学生'  --语句
    declare @id int
    declare @Result nvarchar(20)
    set @id=1
    set @Result=''
    while(@id<=5)
    begin
      select @Result=@Result+CS from @表A where id=@id
      set @id=@id+1
    end
    select @Result--结果
    --------------------
    我是一名学生(1 行受影响)
      

  10.   

    这样就可以了declare @Result nvarchar(20)
    set @Result=''
    select @Result=@Result+CS from @表A
    select @Result--结果
    --------------------
    我是一名学生
      

  11.   

    declare @Result nvarchar(20)
    set @Result=''
    select @Result=@Result+CS from @表A
    select @Result支持这种写法,顶一顶