Free Newsletters:
DatabaseDaily  
Database Journal
Search Database Journal:
 
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum DBA Videos
internet.com

» Database Journal Home
» DBA Videos
» Database Articles
» Database Tutorials
MS SQL
Oracle
MS Access
MySQL
DB2
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» DBA Jobs
» Sitemap

News Via RSS Feed



follow us on Twitter

Marketplace Partners
Be a Marketplace Partner

internet.commerce
Be a Commerce Partner


















Mariposa Bot Shipped With Vodafone Smartphone

IT Job Market Heating Up: Report

Bing Makes Strides But Momentum Stalls

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Database Journal | DBA Support | SQLCourse | SQLCourse2







Finance Developer (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Featured Database Articles

SQL Scripts & Samples

June 8, 2009

Find all numbers in a string



>>Script Language and Platform: SQL Server
This function finds all the numbers in a string.

Example.

select dbo.udf_findallnumbers ('12sfg34')
--results
1234
select dbo.udf_findallnumbers ('asas123')
--results
123
select dbo.udf_findallnumbers ('assd123jdh556jdfd4j56j78')
--results
12355645678
select dbo.udf_findallnumbers ('sadasd')
--results
0
select dbo.udf_findallnumbers ('sadasds65')
--results
65

create table test (name varchar(100))
insert into test select 'A2b4b2b5bb6bb8bb9'
insert into test select 'MAK9974'
insert into test select 'Eiko36DKoike'

select dbo.udf_findallnumbers (name) from test
--results
2425689
9974
36

Author: MAK


Create function dbo.udf_findallnumbers (@inputstring varchar(100))
returns bigint
as
begin
--Author : MAK
--Contact: mak_999@yahoo.com
--Date: Feb 2, 2004
--declare variables
declare @count1 smallint
declare @len1 smallint
declare @word varchar(100)
declare @char1 char
--Assignment
set @word=''
set @count1=1
set @len1 = datalength(@inputstring)

	While @count1 <=@len1
	begin
	set @char1 =substring(@inputstring,@count1,1)
	if ascii(@char1) between 48 and 57 
	begin
	set @word=@word+substring(@inputstring,@count1,1)
	end
	set @count1=@count1+1
	end
return convert(bigint,@word)

end

Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home



Tools:
Add databasejournal.com to your favorites
Add databasejournal.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed

SQL Scripts & Samples Archives








Latest Forum Threads
SQL Scripts & Samples Forum
Topic By Replies Updated
Hello, can anyone help?? terryammon 1 February 7th, 07:39 PM
Question on adding a count to an existing query without effecting original result nelson 2 January 26th, 04:08 PM
search substring (same format) from one column nuonuo 0 January 25th, 11:10 PM
uid find in OID cmontr 1 September 24th, 09:05 AM









The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers