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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 extract number values in a text field

Author  Topic 

wided
Posting Yak Master

218 Posts

Posted - 2011-06-06 : 04:25:53
hello
i have a field looks like this:

Invoice N°0603081 NameClient1
Invoice N°0704071 NameClient2
Invoice number N°0805082 NameClient3

I want to extract only

0603081
0704071
0805082


i can't use substring, because the value not start in the same place

thanks

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-06 : 05:07:10
select SUBSTRING(fld,1,CHARINDEX(' ',fld)-1)
from (select fld = replace(fld,'Invoice N°','') from tbl) a


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -