编码
1001
1005
10086
20035
20037
50060
80083
110106
140129
170152
200175
230198
260221
290244
320267
350290
380313
410336
440359
470382
500405
530428
560451
590474
620497
650520
680543
710566
740589
770612转变成一个数据 1001;1005;10086;20035........
就是把编码中的数据连到一块,单个数据之间用分号隔开,请大家帮帮忙,做接口对应用。

解决方案 »

  1.   


    create table tb(ar varchar(10))
    insert into tb
    select 'a' union all
    select 'b'
    goselect stuff((select ';'+ar from tb for xml path('')),1,1,'')drop table tb/*
    a;b(1 行受影响)
      

  2.   

    /*如何将一列中所有的值一行显示
    数据源
      a
      b
      c
      d
      e
    结果
    a,b,c,d,e
    */create table tb(col varchar(20))
    insert tb values ('a')
    insert tb values ('b')
    insert tb values ('c')
    insert tb values ('d')
    insert tb values ('e')
    go--方法一
    declare @sql varchar(1000)
    set @sql = ''
    select @sql = @sql + t.col + ',' from (select col from tb) as t
    set @sql='select result = ''' + left(@sql , len(@sql) - 1) + ''''
    exec(@sql)
    /*
    result     
    ---------- 
    a,b,c,d,e,
    */--方法二
    declare @output varchar(8000)
    select @output = coalesce(@output + ',' , '') + col from tb
    print @output
    /*
    a,b,c,d,e
    */drop table tb
      

  3.   

    declare @s varchar(1000)
    select @s=isnull(@s+';' , '')+col from tb
    select @s
      

  4.   

    declare @s varchar(1000)
    select @s=isnull(@s+';' , '')+编码 from tb
    select @s
      

  5.   

    Create table tb
    (
    id int identity(1,1),
    name varchar(100)
    )
    Go
    insert into tb
    select '1001' union all
    select '1005' union all
    select '10086'
    Go
    select STUFF((select ';' + name from tb for xml path('')),1,1,'')
    Go
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1001;1005;10086(1 行受影响)
      

  6.   

    if OBJECT_ID('testHL') is not null
    drop table testHL;
    create table testHL
    (aaa varchar(10))
    insert into testHL
    select 'aaa' union all
    select 'bbb' union all
    select 'ccc' union all
    select 'ddd'
    select * from testHL;declare @sql varchar(1000)
    set @sql=''
    select @sql=isnull(@sql,'')+aaa+';' from testHL;