Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Get lowest date
Is there a more elegant way to do the following?...

declare @d1 datetime, @d2 datetime
set @d1 =  '2005-01-01'
set @d2 = '2005-02-01'

select
case
when  datediff(dd,@d2,@d1)
is null
then coalesce(@d1, @d2)
when  (datediff(dd,@d2,@d1
)> 0)
then @d2
else @d1
end


Cheers,..
N

Report this thread to moderator Post Follow-up to this message
Old Post
Neil
04-22-05 12:23 PM


Re: Get lowest date
Try:

SELECT
CASE WHEN @d1<@d2
THEN @d1
ELSE COALESCE(@d2,@d1)
END

or:

SELECT MIN(dt)
FROM
(SELECT @d1 UNION ALL
SELECT @d2)T(dt)

--
David Portas
SQL Server MVP
--


Report this thread to moderator Post Follow-up to this message
Old Post
David Portas
04-22-05 12:23 PM


Re: Get lowest date
That's great! Much cleaner. Thank you.


Report this thread to moderator Post Follow-up to this message
Old Post
NAJH
04-22-05 12:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 04:22 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006