Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Functionality as same Val() function in Access in Sql Server

0.00/5 (No votes)
21 Feb 2011CPOL 13.3K  
SQL
DECLARE @doc VARCHAR(256)

DECLARE @doctemp VARCHAR(256)

SET @doc='467 . 1 2 3 4 .5 6 7 8 9 0 6hhjjjj'

SET @doc = replace(@doc,' ','')

SET @doctemp = substring(@doc,charindex('.',@doc)+1,len(@doc))

SET @doctemp = substring(@doctemp,charindex('.',@doctemp),len(@doctemp))

SET @doc = substring(@doc,1,patindex('%'+@doctemp+'%',@doc)-1)

SELECT CASE

    WHEN @doc LIKE '[0-9.]%'

    THEN CAST(SUBSTRING(@doc, 1, PATINDEX('%[^0-9.]%', @doc+' ') - 1) AS FLOAT)

    ELSE 0

END

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)