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 |
parand
Starting Member
8 Posts |
Posted - 2008-07-07 : 06:00:12
|
Is there any function in SQL2000 which return only the numeric part of a alphanumeric field.For example I would like to be able to convert the following:60ml104 x 125g500ml1 x 30ml185ml28500mlto:60104500118528500Your help is deeply appreciated. |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-07-07 : 06:16:16
|
[code]-- Prepare sample datadeclare @t table( a varchar(40))insert @tselect '60ml' union allselect '10' union allselect '4 x 125g' union allselect '500ml' union allselect '1 x 30ml' union allselect '185ml' union allselect '28' union allselect 'NoNumber' union allselect '500ml'-- Final Queryselect substring(a, 1, case when NonNumIndex = 0 then datalength(a) else NonNumIndex-1 end)from ( select a, patindex('%[a-z]%', a) as NonNumIndex from @t ) twhere NonNumIndex > 1 or NonNumIndex = 0[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
parand
Starting Member
8 Posts |
Posted - 2008-07-07 : 06:48:11
|
Thanks very much.I was hoping to find out if there is any string extraction function which would return the numbers before the first non-numeric character!There might not be such a function! |
 |
|
|
|
|