A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Removing text from a field, leaving a number



 
 
Thread Tools Display Modes
  #1  
Old June 27th, 2008, 04:25 PM posted to microsoft.public.access.queries
PK
external usenet poster
 
Posts: 136
Default Removing text from a field, leaving a number

Help!
I have been running around in circles with this one...

I have a field which contans text and numbers. I need to extract the
number, removing the text completely. Here is the tricky part: there is a
variable number of text characters before and after the number (sometimes no
text after the number).

Example:
abc123def (i want 123)
abcdefg456 (I want 456)
a789 (I want 789)

PLEASE help! I am pulling my hair out!
  #2  
Old June 27th, 2008, 04:36 PM posted to microsoft.public.access.queries
Michel Walsh
external usenet poster
 
Posts: 2,404
Default Removing text from a field, leaving a number

If you can spot the start of the number, it becomes simple:

? val( Mid( "abcd123efg", 5))
123


but that is probably the greatest part of the problem.


Still doable to do it in SQL, though, if you have a driver table, Iotas, one
field, iota, its primary key, with values from 0 to, at least, 255:


SELECT originalField, MAX( val ( mid ( originalField, iotas.iota) ))
FROM yourTable INNER JOIN iotas
ON iotas.iota = len(yourTable.originalField)
GROUP BY originalField


which is based on the fact that val( "a" ) returns 0.

I also assumed your original field do not have NULL value.




Vanderghast, Access MVP


"PK" wrote in message
...
Help!
I have been running around in circles with this one...

I have a field which contans text and numbers. I need to extract the
number, removing the text completely. Here is the tricky part: there is a
variable number of text characters before and after the number (sometimes
no
text after the number).

Example:
abc123def (i want 123)
abcdefg456 (I want 456)
a789 (I want 789)

PLEASE help! I am pulling my hair out!



  #3  
Old June 27th, 2008, 06:10 PM posted to microsoft.public.access.queries
PK
external usenet poster
 
Posts: 136
Default Removing text from a field, leaving a number

Michel,

Absolute GENIUS!

Please run for president. You have my vote.

-PK



"Michel Walsh" wrote:

If you can spot the start of the number, it becomes simple:

? val( Mid( "abcd123efg", 5))
123


but that is probably the greatest part of the problem.


Still doable to do it in SQL, though, if you have a driver table, Iotas, one
field, iota, its primary key, with values from 0 to, at least, 255:


SELECT originalField, MAX( val ( mid ( originalField, iotas.iota) ))
FROM yourTable INNER JOIN iotas
ON iotas.iota = len(yourTable.originalField)
GROUP BY originalField


which is based on the fact that val( "a" ) returns 0.

I also assumed your original field do not have NULL value.




Vanderghast, Access MVP


"PK" wrote in message
...
Help!
I have been running around in circles with this one...

I have a field which contans text and numbers. I need to extract the
number, removing the text completely. Here is the tricky part: there is a
variable number of text characters before and after the number (sometimes
no
text after the number).

Example:
abc123def (i want 123)
abcdefg456 (I want 456)
a789 (I want 789)

PLEASE help! I am pulling my hair out!




  #4  
Old June 27th, 2008, 08:26 PM posted to microsoft.public.access.queries
Klatuu
external usenet poster
 
Posts: 7,074
Default Removing text from a field, leaving a number

Just for fun, this may when the absurd expression of the month award, but it
will take all numberic characters out of a string regardless of where they
are or whether they are contiguous:
replace(replace(replace(replace(replace(replace(re place(replace(replace(replace(x,"0",""),"1",""),"2 ",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8", ""),"9","")
--
Dave Hargis, Microsoft Access MVP


"PK" wrote:

Michel,

Absolute GENIUS!

Please run for president. You have my vote.

-PK



"Michel Walsh" wrote:

If you can spot the start of the number, it becomes simple:

? val( Mid( "abcd123efg", 5))
123


but that is probably the greatest part of the problem.


Still doable to do it in SQL, though, if you have a driver table, Iotas, one
field, iota, its primary key, with values from 0 to, at least, 255:


SELECT originalField, MAX( val ( mid ( originalField, iotas.iota) ))
FROM yourTable INNER JOIN iotas
ON iotas.iota = len(yourTable.originalField)
GROUP BY originalField


which is based on the fact that val( "a" ) returns 0.

I also assumed your original field do not have NULL value.




Vanderghast, Access MVP


"PK" wrote in message
...
Help!
I have been running around in circles with this one...

I have a field which contans text and numbers. I need to extract the
number, removing the text completely. Here is the tricky part: there is a
variable number of text characters before and after the number (sometimes
no
text after the number).

Example:
abc123def (i want 123)
abcdefg456 (I want 456)
a789 (I want 789)

PLEASE help! I am pulling my hair out!




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.