Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Another SQL question
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00694233
Message ID:
00694240
Vues:
11
>Hello,
>
>I'm using this SQL statement:
>
SELECT * from Test WHERE CHRTRAN(cName,' ','') = "GAMMARES"
>
>The result will also give records like "GAMMA". However, "GAMMA" = "GAMMARES" returns .F. Why does the result include these records?
>Thanks.

Christian,

It has to do with how Fox compares strings. The rules are;
SET EXACT OFF (the default)
"ABC" = "ABCD" && .F.
"ABCD" = "ABC" && .T.
Why? The compare algorythm is;
1) Assume equality
2) Comapre one character at a time until the string on the right is exhausted
3) Return the result
This causes "A" = "A" Yes "B" = "B" yes "C" = "C" yes, the stirng on the right is exhausted so they are =
SET EXACT ON
"ABC" = "ABDC" && .F.
"ABCD" = "ABC" && .F.
Algorythm:
1) Assume equality
2) Append  spaces to the shorter string until they are equal lenght
3) comapre one character at a time
4) return the result
now for the third possibility
SET EXACT ON or OFF

"ABC" == "ABCD" && .F.
"ABCD" == "ABC" && .F.
You might thinkj this is the same as SET EXACT ON, but it is not, the algorythm;
1) assume equality
2) comapre one character at a time until the shorter strong is exhausted
3) compare string lenghts
4) return the result
So how they different ?
lcVar1 = "ABC     "
lcVar2 = "ABC"

SET EXACT ON
? lcVar1 = lcVar2 && .T. because the only diff is trailing spaces
? lcVar1 == lcVar2 && .F., becuase they are not the same length
The ONLY way to get an exact comparison of two strings is to use the ==, SET EXACT ON does not give an exact comparison.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform