if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_get_descry_star]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_get_descry_star]
GO

create function f_get_descry_star(@as_source varchar(50))
returns  decimal(16,4)
as
begin 
	if @as_source is null or @as_source='' return 0
	
	--零特殊字符下处理存在问题
 if @as_source='0' or @as_source='0.0' or @as_source='.000' return 0
	
	--特殊字符的处理
	if @as_source = ',' return 0
	
	declare @i int,@ll_len int
	declare @ls_text varchar(50),@ls_result varchar(50)
	select @ls_text=ltrim(rtrim(@as_source))
	select @ll_len=len(@ls_text)
	select @ls_result=''
	select @i=1
	while @i<=@ll_len
	begin
		select @ls_result=@ls_result+char(ascii(substring(@ls_text,@i,1)) - (2 * (@ll_len - @i - 2)))
		select @i=@i+1
	end
	select @ls_result = reverse(@ls_result)	
	
	--对解密之后的字串进行判断是否为数据值型
	if isnumeric(@ls_result) = 0
		set @ls_result = '0'
	
	return cast(@ls_result as decimal(16,4))/10000
end
GO