Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MIN() MAX() in SQL on multiple fields
Message
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Web
Miscellaneous
Thread ID:
01617834
Message ID:
01617914
Views:
33
>I'm going to try this.
>
>
>
>
>PROCEDURE myMin
>LPARAMETERS f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, ;
>            f12, f13, f14, f15, f16, f17, f18, f19, f20
>LOCAL lcFld as String, lnMin as Number
>
>lnCrazyLargeNumber = 9999999
>lnMin = lnCrazyLargeNumber
>
>FOR i = 1 TO PCOUNT()
>	lcFld = "f" + ALLTRIM(STR(i))
>	IF TYPE(lcFld) == "N"
>		IF &lcFld < lnMin
>			lnMin = &lcFld
>		ENDIF 	
>	ENDIF 
>ENDFOR 
>
>IF lnMin == lnCrazyLargeNumber
>	RETURN .null.
>ELSE
>	RETURN lnMin
>ENDIF 	
>
>ENDPROC 
>
>
>and then call it like this (and include cast)
>
>
>SELECT *, CAST(mymin(f1, f2, f3, ...) AS N(10,4)) as mymin FROM mytable
>
PROCEDURE myMin(f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20)
     LOCAL lcParameters as String, lnMin as Number
     IF PCOUNT() < 2
        RETURN NULL
     ENDIF
     lcParameters = [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20]
     lcParameters = [MIN(]+LEFT(m.lcParameters, ATC([,], m.m.lcParameters, PCOUNT())-1)+[)]
RETURN &lcParameters
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform