Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Maximum Function Exist?

Author  Topic 

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2009-06-02 : 08:47:34
Is there a system function that returns the maximum of 2 numerics/ints/floats? Somthing like SELECT MAXIMUM(1,0) would return 1? I know I could write one but I am just wondering if I am missing something.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-02 : 08:57:45
No, there is not such a function.


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-06-02 : 09:09:31
However you can simulate like this

declare @test table(i int identity(1,1),num1 int, num2 int)
insert into @test (num1,num2) select 1,0 union all select 3,6

select i,max(num1) as max_value from
(
select i,num1 from @test
union all
select i,num2 from @test
) as t
group by i


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Ken Blum
Constraint Violating Yak Guru

383 Posts

Posted - 2009-06-02 : 09:14:25
CASE statement will have to do then. Thanks.
Go to Top of Page
   

- Advertisement -