ALTER FUNCTION [dbo].[F_Get_Number] (@S nvarchar(4000))
RETURNS FLOAT
AS
BEGIN
DECLARE @min FLOAT,@max FLOAT,@val FLOAT,@temp nvarchar(50)
IF CHARINDEX(',',@S)>0
BEGIN
SET @temp=Substring(@S,0,CHARINDEX(',',@S))
SET @temp=replace(@temp , '>' , '')
SET @temp=replace(@temp , '<' , '')
SET @temp=replace(@temp , '=' , '')
SET @min= convert(FLOAT,@temp)
SET @temp=Substring(@S,CHARINDEX(',',@S)+1,Len(@S)-CHARINDEX(',',@S))
SET @temp=replace(@temp , '>' , '')
SET @temp=replace(@temp , '<' , '')
SET @temp=replace(@temp , '=' , '')
SET @max= convert(FLOAT,@temp)
SET @val= (@min+@max)/2
END
ELSE IF CHARINDEX(',',@S)>0
BEGIN
SET @temp=Substring(@S,0,CHARINDEX(',',@S))
SET @temp=replace(@temp , '>' , '')
SET @temp=replace(@temp , '<' , '')
SET @temp=replace(@temp , '=' , '')
SET @min= convert(FLOAT,@temp)
SET @temp=Substring(@S,CHARINDEX(',',@S)+1,Len(@S)-CHARINDEX(',',@S))
SET @temp=replace(@temp , '>' , '')
SET @temp=replace(@temp , '<' , '')
SET @temp=replace(@temp , '=' , '')
SET @max= convert(FLOAT,@temp)
SET @val= (@min+@max)/2
END
ELSE
BEGIN
SET @S=replace(@S , '>' , '')
SET @S=replace(@S , '<' , '')
SET @S=replace(@S , '=' , '')
SET @val= convert(FLOAT,@S)
END
RETURN @val;
END