CREATE FUNCTION getItem
 (@fid varchar(15))  
RETURNS nvarchar(500) AS  
BEGIN declare @all nvarchar(500)
set @all=''
select @all=@all+ 证件 + ';' from 随车证件表 where [id]=@fidreturn @all
END

解决方案 »

  1.   

    select identify(1,1) as id, * into #temp0 from yourtable
    create table #temp (A char(10), B varchar(70))
    declare @i int
    declare @max int
    set @i = 1
    select @max = max(id) from #temp0
    while @i <= @max
    begin
      if exists (select * from #temp where A = (select A from #temp0 where id = @i)  )
         update #temp set B = A.B + '+' + B.B from #temp as A, #temp0 as B where A.A = B.A and B.id = @i
      else
         insert #temp select A, B from #temp0 where b.id = @i
      set @i = @i + 1
    end
    select * from #temp order by A