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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separating Alphanumeric from Numeric

Status
Not open for further replies.

JE77

Technical User
Aug 29, 2002
12
IE
I have a field in a table that contains some entries as text and others as numeric entries. The field is defined as A30. What i am trying to do is extract the numeric entries, either by using a query or Tcursor.... Any suggestions.
Thanks in advance
je77
 
je77,

There are a couple of ways you can do this, depending on the results you're after and what you want to do with them.

One way would be to copy the structure of the initial table to a new one and then restructure the A30 field to a numeric one. Next, try to do an INSERT quert that adds the records from the first to the second.

When that process completes, you'll see a PROBLEMS table that shows the alpha-only values (or, more properly, the ones that could not be converted to numbers). (The second table now contains the data that converted properly.)

PROBLEMS is a temporary table, which means it'll disappear quickly (just like ANSWER). So, if you need to retain those troublesome values for any length of time, it's be a good idea to rename PROBLEMS as quickly as possible.

If you want more control over the process, you can also use TCursors and copyToArray() to convert the data. You can discover whether or not a value can be converted using something like this:

Code:
var
   liValid  longInt
endVar

; ... initialization/interim code

try
   liValid = tcSource."A30Field"
onFail
   ; didn't convert.  Add recovery code here.
   liValid = "-1"
endTry

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top