--函数 create function fn_count(@str varchar(8000)) returns int as begin declare @temp table (c varchar(1)) declare @i int while len(@str) > 0 begin insert @temp select left(@str, 1) set @str = right(@str, len(@str) - 1) end delete @temp where c not like '[A-Z]' and c not like '[a-z]' select top 1 @i = count(*) from @temp group by c order by count(*) desc return @i end go--测试 declare @test table (test varchar(8000)) insert @test select 'A666666' union all select 'Ab34343' union all select 'AbdddeD' union all select '8888888' union all select '9999999' select * from @test order by dbo.fn_count(test) desc
create function fn_count(@str varchar(8000))
returns int
as
begin
declare @temp table (c varchar(1))
declare @i int
while len(@str) > 0
begin
insert @temp select left(@str, 1)
set @str = right(@str, len(@str) - 1)
end
delete @temp where c not like '[A-Z]' and c not like '[a-z]'
select top 1 @i = count(*) from @temp group by c order by count(*) desc
return @i
end
go--测试
declare @test table (test varchar(8000))
insert @test
select 'A666666'
union all select 'Ab34343'
union all select 'AbdddeD'
union all select '8888888'
union all select '9999999'
select * from @test order by dbo.fn_count(test) desc