473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Stripping non-numeric chars from a field string - SQL 2000

Hi there - I would like to share this strip of code with our SQL 2000
DBA community. The code below strips all non-numeric characters from a
given string field and rebuilds the string. Very simple, but I had to
build it from scratch due the lack of info on this specific matter. I
am sure there are better solutions out there, although I will be glad
if this script can help anyone. Feel free to modify and comment it
back.

Regards,

Rubem Linn Junior
MCSE, .NET developer
Web Apps Specialist

------------------------------------------------------- BEGIN
---------------------------------------------------

DECLARE @String_Length AS INTEGER -- Length of the given string
DECLARE @Original_String as NVARCHAR(50) -- The field to strip
non-numeric chars
DECLARE @counter as integer -- simple counter variable
DECLARE @Stripped_String as nvarchar(50) -- The field after been
stripped

-- Get the length of the field (string) to be parsed
SELECT @String_Length = len(someStringField) FROM SomeTable WHERE
FilterID = 001

-- Get the field (string) to be parsed
SELECT @Original_String = someStringField FROM SomeTable WHERE
FilterID = 001

-- Set counter variable to 1
SELECT @counter = 1

-- Reset this variable
SELECT @Stripped_String = ''

-- Initiate loop from 1 to the Length of the given string
WHILE (@counter) <= @String_Length
BEGIN

-- Check if the char in the lap is numeric
if substring(@Original_String,@counter,1) LIKE '[0-9]'
BEGIN

-- Load this variable with the non-numeric
-- data stripped from the original string
select @Stripped_String = @Stripped_String +
substring(@Original_String,@counter,1)

END

-- Increment the counter by one
select @counter = @counter + 1

END

-- Print the original string with all characters
PRINT @Original_String

-- Print the numeric data that was stripped out
PRINT RTRIM(LTRIM(@Stripped_String))
Jul 20 '05 #1
1 9954
Thanks for posting it. Here are some other approaches:
http://groups.google.com/groups?selm...40TK2MSFTNGP10

--
Anith
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: scott.watson | last post by:
Hello, I am attempting to attach a .pdf file to an email generated using oracle's utl_smtp. I am working on Oracle9i Enterprise Edition Release 9.2.0.4.0. I beleive that the...
1
by: Andy Jefferies | last post by:
I'm having problems stripping out the whitespace at the beginning of a particular element. In the XML snippet I've highlighted tabs and returns as ^I and ^M respectively: <para> ^I ^I ...
2
by: Patrick | last post by:
Hello, after learning that I was taking a class in VB.NET, I have been drafted to solve all my companies VB/scripting problems - hey, I should know everything; I've already taken 6 classes ;) I...
3
by: Derek | last post by:
Here is a simple template with a non-const static data member: template <typename T> class Foo { public: static int bar; }; template <typename T> int Foo<T>::bar = 42;
8
by: John Buckley | last post by:
Hello! I have a program like this: #include <stdlib.h> int main(void) { /* do stuff */
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
2
by: Peter Rooney | last post by:
hi all, i'm working on a project where i'm marshalling xml files to java objects created with JAXB 1.0 from an xsd schema. the problem is that the marshalling fails (UnexpectedElementException)...
6
by: Medros | last post by:
I understand that you can strip html out of a txt file so that all the information is left is the visable information that is needed (e.g. everything that has < > around is gone). My question is...
7
by: FFMG | last post by:
Hi, I have a form that allows users to comment, add entries and so on. But what a lot of them do is copy and paste directly from MS Word to my forms. almost all browsers will accept the post...
12
by: Stefan Arentz | last post by:
Is there a better way to do the following? attributes = attributeNames = {} n = 1 for attribute in attributes: attributeNames = attribute n = n + 1
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.