Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Oops! MIN & MAX in SQL commands
Message
De
13/02/2003 08:40:46
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00752219
Message ID:
00752639
Vues:
13
>Is this behaviour intentional?
>
>A table exists called DATATABLE and a numeric field NFIELD exists in it. The record pointer is on, say, record #1.
>
>?MAX(NFIELD, 99)
>SELECT MAX(NFIELD, 99) AS COLUMN1 FROM DATATABLE
>
>The first line works fine.
>The second line raises Error 1300 "Function name is missing )."
>
>MIN gives the same error. A pity.
>(I think this has been there since Fox 2xx - any comments?)
>
>Anyone else seen this?
>
>John Burton

John,
max() function is different from SQL max(). SQL max operates on expressions returning a scalar value.
What do you really want to do ? Do aggregation and stil get max of result vs 99 ? Something like max of multiple fields ?

? max(nfield,99) && Would return max of nField, 99
? max(f1, f2, f3, f4) && Would return max of f1..f4 num fields

select iif(nField>99, nField, 99*1) as Column1 from myTable

would return rows as much as myTable has with max of nField,99.
But if your intention is to get max of nField and compare it to 99 (aggregate and return max of nField,99) you can apply SQL max to expression :

select max(iif(nField>99, nField, 99*1)) as Column1 from myTable

or even you can make it shorter using function max() :

select max(max(nField, 99*1)) as Column1 from myTable

Note that in last sample outer max is SQL aggreagation function whilst inner max is VFP's max() function.
You don't need to *1 if your field type is not N(size) but integer.

ie:
CREATE CURSOR test (f1 i, f2 i, f3 i, f4 i)
FOR ix = 1 TO 100
 INSERT INTO test ;
   (f1,f2,f3,f4) VALUES ;
   (RAND()*1000000,RAND()*1000000,RAND()*1000000,RAND()*1000000)
ENDFOR
* Check max, mins created
SELECT MAX(f1), MAX(f2), MAX(f3), MAX(f4) FROM test
SELECT MIN(f1), MIN(f2), MIN(f3), MIN(f4) FROM test
* Get max, mins of all fields
SELECT MAX(MAX(f1,f2,f3,f4)) as MaxValue, ;
	MIN(MIN(f1,f2,f3,f4)) as MinValue FROM test
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform