对列进行操作--游标?
--首先祝各位‘春节快乐,合家幸福!’
--请看代码
--请教是否有另外简单函数或者游标可以实现下面功能?
declare @aa int
set @aa=(select count(*) from 测试的表)
declare @bb int
set @bb=1
declare @xue varchar(max)
set @xue= ' '
while @bb <=@aa
begin
set @xue=@xue+(select bo from 测试的表 where id=@bb)
set @bb=@bb+1
end
--
--
while len(@bb)> =0
begin
print left(@bb,1) --作用简单实例
set @bb=stuff(@bb,1,1, ' ')
end
--
------解决方案--------------------declare @xue varchar(max)
declare @id int
set @xue = ' '
declare id_cursor cursor for
select id from 测试的表
open id_cursor
fetch next from id_cursor into @id
while @@fetch_status=0
begin
set @xue = @xue + (select bo from 测试的表 where id = @id)
fetch next from id_cursor into @id
end
close id_cursor