Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MIN() MAX() in SQL on multiple fields
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Web
Divers
Thread ID:
01617834
Message ID:
01617914
Vues:
32
>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform