create table #table(i char(10),n varchar(50))
insert #table select '1','a'
union select '1','b'
union select '1','c'
union select '1','d'
union select '1','e'
union select '1','f'

declare @str varchar(50)
set @str='' /*注意这里*/
select * from #table
update #table
set @str=(case when i='1' then @str+'a'
else n end),i='1',n=@str
select max(n) from #table

drop table #table

其中需要注意的是,如果没有set @str='',则输出结果为null。还不知道为什么原因。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-09-01
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
相关资源
相似解决方案