或:
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
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
Set @temp = ' '
select @temp = @temp +city from (select distnict city from authors) AA
select @temp
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
Set @temp = ''
update authors set @temp=@temp+city
select @temp
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