Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
baburk
Posting Yak Master
108 Posts |
Posted - 2009-11-10 : 06:36:12
|
| How can I able to get only the integer part from a stringsuppose my string is babu1981the query should produce 1981 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-10 : 07:17:57
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/18/extract-only-numbers-from-a-string.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2009-11-10 : 07:43:25
|
| try with this alsoDECLARE @STR VARCHAR(128)SET @STR = 'BABU1981'SELECT REPLACE(@STR,LEFT(@STR, COALESCE(NULLIF(PATINDEX('%[0123456789]%', @STR) - 1, -1), LEN(@STR))),'') |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-10 : 07:51:37
|
quote: Originally posted by ranganath try with this alsoDECLARE @STR VARCHAR(128)SET @STR = 'BABU1981'SELECT REPLACE(@STR,LEFT(@STR, COALESCE(NULLIF(PATINDEX('%[0123456789]%', @STR) - 1, -1), LEN(@STR))),'')
It will fail for the input BABU1981asdMadhivananFailing to plan is Planning to fail |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
baburk
Posting Yak Master
108 Posts |
Posted - 2009-11-11 : 21:52:10
|
quote: Originally posted by madhivanan
quote: Originally posted by ranganath Hitry with this http://www.kf7.co.uk/sql-server-function-get-numeric.aspx
Yes. It is similar to the one I suggested in my first reply MadhivananFailing to plan is Planning to fail
Thanks for all of your valid reply. |
 |
|
|
|
|
|
|
|