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 |
|
eevans
Starting Member
48 Posts |
Posted - 2009-05-06 : 09:58:04
|
| Hello,I am working with fields that have both text and a number. I would like to run a query to return only the number. The number does not have a set amount of digits. It may occur before, in the middle, or after the text. There are spaces in between the text and the number.Examples:Delta 15324Alpha 82475 Bravo7856 EchoAny suggestions? Thanks. |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-05-06 : 10:00:45
|
| Try patindexdeclare @t table (col1 varchar(20))insert @tselect 'test' union allselect 'test 100' union allselect 'test 101 test' select * from @t where patindex('%[0-9]%',col1) > 0 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-05-06 : 10:12:00
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2007/12/18/extract-only-numbers-from-a-string.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
eevans
Starting Member
48 Posts |
Posted - 2009-05-06 : 10:26:55
|
| Thanks all! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-05-07 : 02:31:01
|
quote: Originally posted by eevans Thanks all!
There suggested solutions will give you different result. Which one do you need?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|