日期:2014-05-17 浏览次数:20613 次
set nocount on
declare @table table(val char(1))
declare @s varchar(8000),@i int
set @s='bbdgegpoakfoa'
set @i=1
while @i<=LEN(@s)
begin
insert into @table select SUBSTRING(@s,@i,1)
set @i=@i+1
end
set @s=''
select @s=@s+val from @table order by val
print @s
/*
aabbdefggkoop
*/
declare @a int,@d varchar(max),@f varchar(max)
declare @x table(v varchar(1))
set @d='bbdgegpoakfoa'
select @a=1
while(@a<=len(@d))
begin
insert into @x(v) values(substring(@d,@a,1))
select @a=@a+1
end
select @f=isnull(@f,'')+v from @x order by v
select @f 'f'
/*
f
-------------------------
aabbdefggkoop
(1 row(s) affected)
*/