jawadfrhad
Programmer
* your code here
hi all
need to find max value among fields AND PRINT FIELD NAME
same
hi all
need to find max value among fields AND PRINT FIELD NAME
same
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
SELECT recno() as row, "f1" as column f1 as f FROM yourtable
UNION
SELECT recno() as row, "f2" as column f2 as f FROM yourtable
...
INTO CURSOR UnionedData
Select hi.row, hi.highest, u2.column as highest_name from ;
(SELECT row, Max(f) as highest;
From UnionedData u1;
GROUP BY row) hi;
Left Join UnionedData u2 on u2.row=hi.row ;
having u2.f=hi.highest
* step 1: populate highest:
replace all highest with max(f1,f2,f3,f4,f5)
* step 2: determine highest_name
replace all highest_name with "f5" for f5=highest
replace all highest_name with "f4" for f4=highest
replace all highest_name with "f3" for f3=highest
replace all highest_name with "f2" for f2=highest
replace all highest_name with "f1" for f1=highest
replace all highest_name with icase(f1=highest,"f1",...,f4=highest,"f4","f5")
LOCAL lni, lnValue
CREATE CURSOR csrResults (iResults I, cName C(5))
CREATE CURSOR curTemp (f1 I, f2 I, f3 I)
FOR lni = 1 TO 25
INSERT INTO curTemp VALUES ( Int(Rand() * 25) + 1, Int(rand() * 25), Int(Rand() * 25) + 2)
ENDFOR
LOCATE
BROWSE NOWAIT
SCAN
lnValue = 0
lcName = ""
FOR lni = 1 TO FCOUNT()
IF EVALUATE(FIELD(lni)) > lnValue
lnValue = EVALUATE(FIELD(lni))
lcName = FIELD(lni)
ENDIF
IF lni = FCOUNT()
INSERT INTO csrResults VALUES (lnValue, lcName)
ENDIF
ENDFOR
ENDSCAN
SELECT csrResults
BROWSE
CLOSE ALL
SELECT TheTable
REPLACE ALL Highest WITH MAX(F1, F2, F3, F4, F5)
REPLACE ALL Highest_Name WITH ;
ICASE( ;
F1 = Highest, "F1", ;
F2 = Highest, "F2", ;
F3 = Highest, "F3", ;
F4 = Highest, "F4", ;
F5 = Highest, "F5" )
Me said:I'm assuming that there always exact five fields to be tested, and that these are always named F1, F2, etc.
SELECT TheTable
LOCAL lcF1, lcF2, lcF3, lcF4, lcF5
lcF1 = FIELD(1)
lcF2 = FIELD(2)
lcF3 = FIELD(3)
lcF4 = FIELD(4)
lcF5 = FIELD(5)
REPLACE ALL Highest WITH ;
MAX(EVALUATE(lcF1), EVALUATE(lcF2), EVALUATE(lcF3), EVALUATE(lcF4), EVALUATE(lcF5))
REPLACE ALL Highest_Name WITH ;
ICASE( ;
EVALUATE(lcF1) = Highest, lcF1, ;
EVALUATE(lcF2) = Highest, lcF2, ;
EVALUATE(lcF3) = Highest, lcF3, ;
EVALUATE(lcF4) = Highest, lcF4, ;
EVALUATE(lcF5) = Highest, lcF5 )