if object_id('fnTest_ASC') is not null
drop function fnTest_ASC
GO
----创建字符ASCII码值计算函数
create function fnTest_ASC(@str varchar(100))
returns int
as
begin
declare @asc int
set @asc = 0
while @str <> ''
begin
set @asc = @asc + ascii(substring(@str,1,1))
set @str = stuff(@str,1,1,'')
end
return @asc
end
GO
----比较字符串
declare @a varchar(10),@b varchar(10)
set @a=',2,4,7'
set @b=',7,2,4'
select case when dbo.fnTest_ASC(@a) = dbo.fnTest_ASC(@b) then '相等' else '不相等' end