Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why doesn't this work?
Message
 
 
To
30/08/1999 17:49:36
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00259423
Message ID:
00259992
Views:
17
>>I have a field in a table with values like "T1110X" and "T1110.12". I want to extract just the number part, which always starts on space 2. So I do ?TRAN(VAL(SUBS(myField,2))). For each field it works great showing: "1110" and "1110.12" respectively. Here's the weird part: If I use a SELECT statement: SELECT TRAN(VAL(SUBS(myField,2))) FROM myTable WHERE !empty(myField) -- for the same records I get "11" and "11". Why wouldn't this work? As a work around I am doing: SELECT LEFT(TRAN(VAL(SUBS(myField,2))),15)..... and it works fine. Can anyone teach me something here? I figure I wasted so much time on this, I should at least learn something out of it!
>>
>>TIA,
>>Marcus.
>
>well...
>
>1. If you don't pad the field then the first record selected will determine the length of the field... so, if your first record is....
>
>U11
>
>and your second is...
>
>T1123
>
>YOu will get 11 for both, since the field in your cursor is going to be lenght of two.
>
>Also, if you are looking for character, why are you using VAL?
>
>What the left statment is doing is padding all values to a length of 15, so that there is room to hold all the values.
>
>Look at your first record and see if it is a two digit length.
>
>BOb

Thanks Bob,
That is exactly it. The first record is two digits. I'm just starting to use SQL selects rather than looping through tables all the time. Thanks for the lesson. I'm using VAL because, the number always starts in position 2 but isn't consistent. Example: 'T20TT' or 'T21111' or 'T22231L'. I figured VAL would work well for just grabbing the number portion.

Marcus.
Previous
Reply
Map
View

Click here to load this message in the networking platform