一个table得出以下结果
field
c
h
i
l
d我想得到
field0
child这样的结果

解决方案 »

  1.   

    create table tb(field varchar(5))
    insert into tb select 'c'
    union all select 'h'
    union all select 'i'
    union all select 'l'
    union all select 'd'select * from tbdeclare @s varchar(100)
    set @s=''
    select @s=@s+field from tb
    select @s as fielddrop table tb
      

  2.   

    if object_id('testfunc') is not null drop function testfunc
    go
    create function testfunc() returns varchar(100)
    as
    begin
      declare @s varchar(100)
      set @s = ''
      select @s = @s + field
      from tablename
      return(@s)
    end
    go
    select dbo.testfunc()
    drop function testfunc
      

  3.   


    declare @vStr nvarchar(2000)
    set @vStr=''
    select @vStr=@vStr+field
    from TableName