Groups | Blog | Home
all groups > sql server (alternate) > february 2006 >

sql server (alternate) : Searching/Estracting numerical data


KR
2/6/2006 1:53:35 PM
KR
Feb 6, 1:48 pm show options

Newsgroups: microsoft.public.access.forms
From: "KR" <kra...@bastyr.edu> - Find messages by this author
Date: 6 Feb 2006 13:48:00 -0800
Subject: Extract Number from Fields - SQL
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse

I am new to the SQL world, and I am trying to come up with a script
that will extract only the numerical data from a column of varchar
data type . There is not a pattern to the data entered, except that
the data that
I am looking to extract is a three digit number. If someone could
point me in the right direction that would be great.


Thanks in advance
KR
Erland Sommarskog
2/6/2006 10:24:34 PM
KR (kraman@bastyr.edu) writes:
[quoted text, click to view]

SELECT cast(col as int) FROM tbl WHERE col LIKE '[0-9][0-9][0-9}'


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Erland Sommarskog
2/6/2006 11:19:18 PM
Hugo Kornelis (hugo@perFact.REMOVETHIS.info.INVALID) writes:
[quoted text, click to view]

patindex, you mean, n'est-ce pas?



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Hugo Kornelis
2/6/2006 11:53:52 PM
[quoted text, click to view]

Hi KR,

The function you would use to find where a three digit sequence in
varchar data is located is

POSINDEX ('%[0-9][0-9][0-9]%', CharData)

--
Hugo Kornelis
2/7/2006 12:34:00 AM
[quoted text, click to view]

Ah, oui, c'est vrai!!

Thanks for the catch, Erland!

--
KR
2/7/2006 8:39:22 AM
Thanks much


KR
AddThis Social Bookmark Button