0

I have a table with two column as :

serial_number
1
2
3

dateOfAppoinement
2011-06-30 00:39:04.130
2011-06-30 00:40:01.130
2011-06-30 00:49:04.130

I want to get the highest serial_number of a day. I have to avoid the time part. I'm just using the date part.

Can anyone tell me how can I do this?

bobs
  • 21,844
  • 12
  • 67
  • 78
sohel14_cse_ju
  • 2,481
  • 9
  • 34
  • 55

2 Answers2

1

I updated my answer to use Convert like snkmchnb suggested. However in SQL Server 2008 there is a DATE datatype that is just the date portion of the year so you don't have to specify the 120 code. I tested this and it works perfectly and the SQL is pretty straight forward.

SELECT
    MAX(serial_number),
    CONVERT(DATE, dateOfAppointment) as [Day]
FROM
    #TempSerialsByDate
GROUP BY
    CONVERT(DATE, dateOfAppointment)
N. Warfield
  • 346
  • 2
  • 14
0

I think this select solves your problem, can't figure if it is the best way:

select dateadd(dd,0, datediff(dd,0, dateOfAppoinement ))
from your_table where serial_number = (select max(serial_number) form your_table)

How truncate date in sql server can be found here: How can I truncate a datetime in SQL Server?

Community
  • 1
  • 1
RMalke
  • 4,048
  • 29
  • 42