Click here to Skip to main content
Click here to Skip to main content

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

By , 21 Feb 2011
 
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)

About the Author

Vivek.Net
Software Developer (Senior) Accenture
India India
Member
I am a Dot Net Developer working in MNC. I am interested to learn new technologies. I am always trying to improve my skills.
 
MCTS:ASP.NET 3.5
MCTS:WCF 3.5

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 21 Feb 2011
Article Copyright 2011 by Vivek.Net
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid