您的位置:首页 > 博客中心 > 数据库 >

自己写的sql排序

时间:2022-03-10 17:46

create function dbo.Fn_Sort (  @str varchar(1024) )

returns nvarchar(100)

as

begin

declare @tb table(num int)

declare @strtemp varchar(100)

declare @cID varchar(100)

declare @cEidx int

declare @relation_code varchar(1024)

set @relation_code=@str + ‘,‘

while charindex(‘,‘,@relation_code) > 0

begin  

set @cEidx = charindex(‘,‘,@relation_code,1) 

 set @cID = substring(@relation_code,1,@cEidx-1)

 set @relation_code=substring(@relation_code,@cEidx+1,len(@relation_code)-@cEidx)  

 insert into @tb values(@cID)

end

select @strtemp=isnull(@strtemp+‘,‘,‘‘)+rtrim(num) from @tb order by num return @strtemp

end

 

select dbo.Fn_Sort(‘3,2,35,6,4,8‘)

自己写的sql排序,布布扣,bubuko.com

热门排行

今日推荐

热门手游