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.
Author |
Topic |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-05-07 : 23:24:29
|
carDate2012-12-31 19:35:14.2732012-12-31 19:37:51.5202013-01-01 03:37:44.8232013-01-01 03:35:10.727how can i get min datetime.i tried select min(carDate) but it still return both value.carDate2012-12-31 19:35:14.2732012-12-31 19:37:51.520it suppose to get only this:carDate2012-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) |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-08 : 00:11:02
|
[code]SELECT carDateFROM (SELECT DENSE_RANK() OVER (ORDER BY carDate) AS rnk,* FROM table)tWHERE Rnk=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|