Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL and Ranges
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00398875
Message ID:
00398883
Views:
16
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform