或:
declare @count int
declare @i
declare @temp nvarchar(4000)
create table #temp
(id int identity(1,1);
 city char(20))
insert into #temp (city) select city from authors
select @count = count(*) from #temp
set @i = 0
set @temp = ''
while @i < @count
  begin
    select @temp = @temp + city from #temp where id = @i
    set @i = @i +1
  end
select @temp

解决方案 »

  1.   

    declare @temp nvarchar(4000)
    Set @temp = ' '
    select @temp = @temp +city from (select distnict city from authors) AA
    select @temp
      

  2.   

    或:declare @a table (a1 varchar(100))
    declare @b varchar(1000)
    set @b=''
    insert @a values('a')
    insert @a values('b')
    insert @a values('c')update @a set @b=@b+a1
    select @b
      

  3.   

    绝对经典:declare @temp nvarchar(4000)
    Set @temp = ''
    update authors set @temp=@temp+city
    select @temp
      

  4.   

    declare @temp nvarchar(4000)
    declare @tmpCity nvarchar(4000)declare city_cursor cursor for select distinct city from authorsSet @temp = ' '
    open city_cursor
    fetch next from city_cursor into @tmpCity 
    while @@FETCH_STATUS = 0
    begin
        set @temp=@temp+@tmpCity 
        fetch next from city_cursor into @tmpCity
    end
    close city_cursor
    deallocate city_cursorprint @temp
      

  5.   

    谢谢大家,虽然用游标可以达到效果,但我需要用一条语句实现,因此我采纳了CrazyFor(Fan)的sql语句,再次感谢大家。