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

Get the numberportion out of a stringfield

Status
Not open for further replies.

stillsteam

Programmer
Apr 2, 2004
52
SE
Hello
Using CR 8.5 and SQL 2000
I´ve been searching in the posts but with the Keyword search not online that will take too long.
I need to extract the numberportion of a stringfield{altenhetkod}. I will use the output later so I need it to be a numberfield.
The reports is grouped on item no.

{altenhetkod} contains of these examples:
Item 1 {altenhetkod} Expected output
pal 100 100
yfp 20 20
ifp10 10
5bnt/pal 5
st 1 1
Item 2
pal 2455 2455

Item 3 pal 125 125
yfp 20 20
For this report I am mostly interested in the maximum value, that I can easily do, but at some point I might also want to group by altenhetkod.

TIA Jonas


 
Try the following formula:

numbervar counter := 0;
numbervar i := len({table.altenhetkod});
stringvar result := "";

for counter := 1 to i do(
if isnumeric({table.altenhetkod}[counter]) then
result := result + {table.altenhetkod}[counter]);
val(result)

-LB
 
Works great!
Thank you LB
I don´t know much about varibles, could you explain how this formula work?

TIA Jonas
 
The formula looks at each character in the string (i = up to the length of the string) and says that if the character is numeric, add it to the result. Finally, the val() function converts the result to a number.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top