Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max() statement assistance required 1

Status
Not open for further replies.

jason321

IS-IT--Management
Joined
Sep 5, 2008
Messages
3
Location
CA
I'm trying to make a query in Access but cannot figure out how to do it - here is what works in Sql Server
select rate1, rate2,
(select max(rate)
from (select rate1 as rate
union all
select rate2 as rate
) as a) as MaxRate
from dbo.rates;
Please help - thanks
 
Perhaps this ?
Code:
SELECT rate1, rate2,
 (SELECT Max(rate) FROM (
     (SELECT rate1 AS rate FROM tblRates
      UNION ALL SELECT rate2 FROM tblRates
     ) AS A
 ) AS MaxRate
FROM tblRates

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply PHV -
It gives me a column at least but it takes the max of all the rates and puts that value in every field - seems some sort of cartesian product too for some reason. I've tried grouping but that doesn't seem to work either.
 
Sorry, misunderstood your unformulated question ...
SELECT rate1, rate2, IIf(rate1<rate2,rate2,rate1) AS MaxRate FROM tblRates

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That's the one! Thanks PHV
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top