RSS

Find Maximum between Two Numbers‏

02 Sep

Example 1

DECLARE @Value1 DECIMAL(5,2) = 9.22
DECLARE @Value2 DECIMAL(5,2) = 8.34
SELECT (0.5 * ((@Value1 + @Value2) + ABS(@Value1 – @Value2))) AS MaxColumn
Example 2

DECLARE @Value1 DECIMAL(5,2) = 9.22
DECLARE @Value2 DECIMAL(5,2) = 8.34
SELECT CASE WHEN @Value1 > @Value2 THEN @Value1 ELSE @Value2 END As MaxColumn

Example 3

DECLARE @Value1 DECIMAL(5,2) = 9.22
DECLARE @Value2 DECIMAL(5,2) = 8.34
DECLARE @VALUE3  DECIMAL(5,2)= 15
DECLARE @RESULT INT
SELECT @RESULT = (SELECT  CASE WHEN @Value1 > @Value2 THEN @Value1 ELSE @Value2 END AS MaxColumn)
SELECT CASE WHEN @VALUE3 > @RESULT THEN @VALUE3 ELSE @RESULT END AS MaxColumn

 
Leave a comment

Posted by on September 2, 2011 in Script

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s