Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why doesn't this work?
Message
 
À
30/08/1999 17:49:36
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00259423
Message ID:
00259992
Vues:
18
>>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform