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 2005 Forums
 Transact-SQL (2005)
 a function to return the smaller of 2 arguments

Author  Topic 

theboyholty
Posting Yak Master

226 Posts

Posted - 2010-02-19 : 09:11:51
Is there a function to return the smaller of 2 arguments? i.e. 2 dates. I know i could use datediff but that seems messy.

Thanks.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-19 : 09:18:50
select case when date1<date2 then date1 else date2 end from your_table

Madhivanan

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

theboyholty
Posting Yak Master

226 Posts

Posted - 2010-02-19 : 09:20:48
Hmm yep i did that end the end, I just wondered if there was a function along the lines of coalesce.

thanks.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-19 : 09:25:29
you could do this also

SELECT pk,MIN(dateval)
FROM
(
SELECT date1 AS dateval,pk FROM table
UNION ALL
SELECT date2,pk FROM table
)t
GROUP BY pk


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-19 : 10:15:20
quote:
Originally posted by theboyholty

Hmm yep i did that end the end, I just wondered if there was a function along the lines of coalesce.

thanks.

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk The official unofficial website of Bury Football Club


In ORACLE there is a function called least which does what you want. In SQL Server there is no such function

Madhivanan

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

- Advertisement -