Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL and Ranges
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00398875
Message ID:
00398883
Vues:
11
>Using a SQL statement, I like to be able to to look at a field and if it's in a certain range, have it give a code in another field. Lets say grades for example, range 90 to 100 'A', 80-89 'B', 70-79 'C'. So if numgrade = 89, i like to have alphagrade = 'B'
>
>TIA,
>
>Jim

SELECT numgrade, get_alphagrade(numgrade) AS alphagrade ;
FROM my_marks ;
INTO CURSOR TEMP

and have function like this in your procedure file.


FUNCTION get_alphagrade
LPARAMETER tnNumGrade
lcReturn = ""
DO CASE
CASE BETWEEN(tnNumGrade, 70,79)
lcReturn = "C"
CASE BETWEEN(tnNumGrade, 80,89)
lcReturn = "B"
CASE BETWEEN(tnNumGrade, 90,100)
lcReturn = "A"
ENDCASE
RETURN lcreturn
ENDFUNC

RETURN

In many cases it may be just enough to have IIF in your select statement like:
SELECT field1, IIF(field2 = 1, "YES","NO") AS myOtherfield FROM...
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform