Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 116
sqlserver 96
BRH 78
#SQLServer 66
#TSQL 56
SQL Server 34
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2012 7
June 2011 7
November 2007 7
August 2012 6
May 2012 6
November 2011 6
August 2011 6
October 2011 6

Madhivanan's TSQL Blog

Finding maximum of Two numbers

Jun 27 2011 2:58AM by Madhivanan   

Pinal Dave, in his site, posted an interesting solution on finding out maximum number between two numbers. Here are some alternate methods that I know

Method 1 : Use max function

declare @value1 decimal(5,2) = 9.22
declare @value2 decimal(5,2) = 8.34

select max(val) from
(
	select @value1 as val union all
	select @value2 
) as t

Method 2 : Use Top function

declare @value1 decimal(5,2) = 9.22
declare @value2 decimal(5,2) = 8.34
select top 1 val from
(
	select @Value1 as val union all
	select @Value2 
) as t order by val desc

Method 3 : Use VALUES clause(applicable from version 2008 onwards)
Find more information about it here

declare @value1 decimal(5,2) = 9.22
declare @value2 decimal(5,2) = 8.34

select max(val) from (values (@Value1),(@Value2)) as t(val)

Method 4 : Use row_number() function(applicable from version 2005 onwards)
Findout what you can do with row_number function here

declare @value1 decimal(5,2) = 9.22
declare @value2 decimal(5,2) = 8.34


select val from
(
	select val,row_number() over (order by val desc) as sno from
	(
		select @value1 as val union all
		select @value2 
	) as t
) as t
where sno=1

Tags: t-sql, sql_server, sqlserver, tsql, BRH, maximum,


Madhivanan
3 · 39% · 12472
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • You can also use CROSS APPLY. Please see my comment on Values Clause in SQL Server 2008.

    commented on Jun 30 2011 12:29PM
    ErikEckhardt
    65 · 3% · 891
  • I think that a better approach is just:

    declare @value1 decimal(5,2) = 9.22 declare @value2 decimal(5,2) = 8.34

    SELECT CASE WHEN @value1>@value2 THEN @value1 ELSE @value2 END

    commented on Jul 15 2011 6:17AM
    aaiello
    605 · 0% · 58

Your Comment


Sign Up or Login to post a comment.

"Finding maximum of Two numbers" rated 5 out of 5 by 1 readers
Finding maximum of Two numbers , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]