您的位置:首页 > 其它

字符串排序输出函数

2007-04-29 17:28 411 查看
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_Ord]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_Ord]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

CREATE function fn_Ord(@str varchar(4000),@flg varchar(10))
returns varchar(4000)
as
begin
declare @a table (a nvarchar(2))
declare @s varchar(4000)
declare @i int
set @s=''
set @i=1
while @i<len(@str)
begin
insert @a select substring(@str,@i,1)
set @i=@i+1
end
if @flg='asc'
select @s=@s+a from @a order by a
else
select @s=@s+a from @a order by a desc

return @s

/*
select dbo.fn_Ord('gdadfasdf','asc')
*/
end

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐