473,386 Members | 1,702 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,386 software developers and data experts.

selecting only numeric data from a string

Hello,

I need to be able to select only the numeric data from a string that is
in the form of iFuturePriceID=N'4194582'

I have the following code working to remove all the non-numeric text
from before the numbers, but it is still leaving the single quote after
the numbers, i.e. 4194582'

Any ideas or suggestions how to accomplish that? Thanks in advance.

Declare @TestData varchar(29)
Set @TestData = "iFuturePriceID=N'4194582'"
Select Substring(@TestData, patindex('%[0-9]%', @TestData),
Len(@TestData))

TGru

*** Sent via Developersdex http://www.developersdex.com ***
Jan 12 '06 #1
3 10218
len(@TestData) causes it to take the entire string after the first
number. you need to trim this down by the length of your number...

SELECT substring(@TestData, patindex('%[0-9]%', @TestData),
len(@TestData) - patindex('%[0-9]%', @TestData) - patindex('%[0-9]%',
reverse(@TestData)) + 2)

Tim Groulx wrote:
Hello,

I need to be able to select only the numeric data from a string that is
in the form of iFuturePriceID=N'4194582'

I have the following code working to remove all the non-numeric text
from before the numbers, but it is still leaving the single quote after
the numbers, i.e. 4194582'

Any ideas or suggestions how to accomplish that? Thanks in advance.

Declare @TestData varchar(29)
Set @TestData = "iFuturePriceID=N'4194582'"
Select Substring(@TestData, patindex('%[0-9]%', @TestData),
Len(@TestData))

TGru

*** Sent via Developersdex http://www.developersdex.com ***


Jan 12 '06 #2
The issue there is that the numbers are of varying lengths, and it might
not always just be a single quote at the end. So, I was hoping to be
able to just extract the numerics without having to deal with positions
and length of the numeric portion. I.e. why can't I just grab alpha or
numeric or non alpha numeric from the whole string??
:-) Seems like that should be easier to do than it is...

TGru

*** Sent via Developersdex http://www.developersdex.com ***
Jan 12 '06 #3
tgru wrote:
The issue there is that the numbers are of varying lengths, and it
might not always just be a single quote at the end. So, I was hoping
to be able to just extract the numerics without having to deal with
positions and length of the numeric portion. I.e. why can't I just
grab alpha or numeric or non alpha numeric from the whole string??
:-) Seems like that should be easier to do than it is...


You can for example use charindex to find the terminating single quote.

You cal also install Oracle 10 which supports regular expressions.
Honestly, is this stored in the DB? If so, I'd try to make it two columns
if possible.

HTH

robert

Jan 12 '06 #4

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

Similar topics

1
by: JuniorLinn | last post by:
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...
5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
3
by: success_ny | last post by:
Does anyone have a code snippet to compare those values so I can sort the array of alpha-numeric values that include both characters and integers in it? I.e., if we have values like 4236 and...
6
by: Matik | last post by:
Hello all, I've following problem. Please forgive me not posting script, but I think it won't help anyway. I've a table, which is quite big (over 5 milions records). Now, this table contains...
3
by: Joakim Olesen | last post by:
Hi I have an issue with an asp page that reads from an Excel file. I read the file using OLEDB. I create a new Excel file using "MS Excel 2003" and put the following data into a sheet called...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
42
by: Dooglo | last post by:
I'm new VB and programming all together, but I'm getting he hang of it. My question is; I'm writting a program to figure square feet and yards when the user inputs "Length in feet and inch (...
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
4
by: Doug Gray | last post by:
Folks, I am looking for a fast but most importantly a bullet proof method to pass and NMEA data stream (GPS output) ascii numeric strings. The best I can offer is: def fint(a): try: return...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.