Link to home
Start Free TrialLog in
Avatar of Ron Kidd
Ron KiddFlag for Australia

asked on

Select the Greater of 3 variables and return a different variable SQL 2014

I am Using SQL Server 2014
I have a stored procedure that has 6 parameters.


I need to find the Greatest Order Value and Return the OrderID.

I can select the Max Order Value but I need the OrderID of the Highest Order Value

SELECT MAX(v) FROM (VALUES (@OrderValue1), (@OrderValue2), (@OrderValue3)) AS value(v)

Many Thanks
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ron Kidd