Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Numeric characters only

Status
Not open for further replies.
Nov 29, 2002
64
0
0
US
Hello everyone, is it there a way to select the numeric characters of a cell using just SQL?

My records:
Activity_Desc
(55) COMUNICACIONES
03-SEGUROS
ALIMENTOS Y BEBIDAS - 43
BIENES RAICES (68)
CONSTRUCCION (14 ) CARTOGRAFIA

My expected results
55
03
43
68
14

Tnxs!!!

Alfredo
 
In a standard code module create a function like this:
Code:
Public Function getNum(myField)
  Dim s As String, l As Long, x As String
  If Trim(myField & "") = "" Then
    getNum = myField
    Exit Function
  End If
  For l = 1 To Len(myField)
    x = Mid(myField, l, 1)
    If (x >= "0" And x <= "9") Then
      s = s & x
    End If
  Next l
  getNum = s
End Function
Then in your query:
SELECT Activity_Desc, getNum([Activity_Desc]) AS NumOnly
FROM yourTable.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, unfortunatelly I've never used access modules, does it work by just saving the module as "getNum" and then running the query???
Sorry for the simple question....
 
Pretty much ... but you don't want to save it as "getNum" because that's the name of a Sub inside the module. Just call it "myModule" or something generic. You can add more subs and functions to it as the need arises.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top