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
 General SQL Server Forums
 New to SQL Server Programming
 min datetime

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-05-07 : 23:24:29
carDate
2012-12-31 19:35:14.273
2012-12-31 19:37:51.520
2013-01-01 03:37:44.823
2013-01-01 03:35:10.727

how can i get min datetime.

i tried select min(carDate) but it still return both value.

carDate
2012-12-31 19:35:14.273
2012-12-31 19:37:51.520

it suppose to get only this:
carDate
2012-12-31 19:35:14.273

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-05-08 : 00:08:09
What data type is carDate? Show the exact query you are using, and the table definition.

This works as expected:

Declare @t TABLE (carDate datetime)

insert @t values('2012-12-31 19:35:14.273')
insert @t values('2012-12-31 19:37:51.520')
insert @t values('2013-01-01 03:37:44.823')
insert @t values('2013-01-01 03:35:10.727')

select min(carDate) from @t
-----------------------
2012-12-31 19:35:14.273

(1 row(s) affected)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-08 : 00:11:02
[code]
SELECT carDate
FROM
(SELECT DENSE_RANK() OVER (ORDER BY carDate) AS rnk,*
FROM table
)t
WHERE Rnk=1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -