Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Oops! MIN & MAX in SQL commands
Message
From
19/02/2003 07:31:31
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00752219
Message ID:
00754867
Views:
24
>Cetin
>
>>>>select max(max(nField, 99*1)) as Column1 from myTable
>>>Are you sure this one will work?
>>>
>>>>Note that in last sample outer max is SQL aggreagation function whilst inner max is VFP's max() function.
>>>Inner one won't work!
>
>>John,
>>Did you try the sample ? Inner one works as arithmetiuc max.
>>Cetin
>
>Correction! It works - but what exactly is it for? I _still_ want my arithmetic MAX().
>
>Waaah!
>
>John Burton

OK John,
But giving some value samples if you can tell exatcly what you want to get as a result it'd be better :)
nField
------
10
20
30
110
98
What do you want the result set be ?
nField
------
99
99
99
110
99

*Or :
nField
------
110
If the latter one :
select max(max(nField,99)) ...
would work.

If the first one :
Then your chances are less. Either you cshould create and use an UDF. ie :
CREATE CURSOR myTest (f1 i, f2 i, f3 i)
INSERT INTO myTest VALUES (10,20,30)
INSERT INTO myTest VALUES (20,30,40)
INSERT INTO myTest VALUES (30,40,50)
INSERT INTO myTest VALUES (40,50,60)
INSERT INTO myTest VALUES (120,20,70)
INSERT INTO myTest VALUES (50,60,70)

SELECT *, myMAX(f1,f2,f3) as myMax FROM myTest

FUNCTION myMax
LPARAMETERS p1,p2,p3 
RETURN MAX(99,p1,p2,p3)*1
Or have a unique field and group on it (to make SQL max work on indiviual records). ie:
CREATE CURSOR myTest (pkID i, f1 i, f2 i, f3 i)
INSERT INTO myTest VALUES (1,10,20,30)
INSERT INTO myTest VALUES (2,20,30,40)
INSERT INTO myTest VALUES (3,30,40,50)
INSERT INTO myTest VALUES (4,40,50,60)
INSERT INTO myTest VALUES (5,120,20,70)
INSERT INTO myTest VALUES (6,50,60,70)

SELECT *, MAX(MAX(99,f1,f2,f3)*1) as myMax FROM myTest GROUP BY pkID
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
Previous
Reply
Map
View

Click here to load this message in the networking platform