I have been given three values:
@lHeight. I need to take these
DECIMAL(4,2) values and set the values of
@lMin with the values I've been given in order of value. So whichever value of
Height is the greatest will be stored in
Max, and the second created in
Mid, and the lowest value in
Note: I am limited to Microsoft SQL Server 2008.
-- Declarations are for testing purposes only DECLARE @lLength DECIMAL(4,2) = CAST('1.0' AS DECIMAL(4,2)) DECLARE @lWidth DECIMAL(4,2) = CAST('2.0' AS DECIMAL(4,2)) DECLARE @lHeight DECIMAL(4,2) = CAST('3.0' AS DECIMAL(4,2)) DECLARE @lMax DECIMAL(4,2) DECLARE @lMid DECIMAL(4,2) DECLARE @lMin DECIMAL(4,2) --Determine which is higher and store it. IF @lLength > @lWidth BEGIN SET @lMax = @lLength SET @lMid = @lWidth END ELSE BEGIN SET @lMax = @lWidth SET @lMid = @lLength END --Now determine where the 3rd value needs to be inserted IF @lHeight < @lMid BEGIN SET @lMin = @lHeight END ELSE IF @lHeight < @lMax BEGIN SET @lMin = @lMid SET @lMid = @lHeight END ELSE BEGIN SET @lMin = @lMid SET @lMid = @lMax SET @lMax = @lHeight END --This select is for testing purposes only SELECT @lMax as MAX, @lMid AS MID, @lMin AS MIN
The code above works, and I added declarations and a select to make that readily apparent. I am looking for a general review of this operation, perhaps a better way to do this. You can criticize the naming convention, but that is something I have no control over. Also, I do not have to worry about scalability of this operation unless our world gets a 4th physical dimension in the near future.