PDA

View Full Version : Group the records with date ONLY in SQL.


NinjaTurtle
04-09-2005, 08:31 AM
My problem is i cant group the records with date ONLY in SQL statement.
This is some sample records in my table, eg:

Name LogDateTime
------ -------------
John 1/1/2005 02:03:04
Alice 1/16/2005 04:55:55
Hon 1/16/2005 13:33:56
Frank 1/16/2005 18:44:01
Ron 2/28/2005 12:22:33
Toy 2/28/2005 04:17:19

What i want is to group them by LogDateTime, group it just with date not time.

Result should be:

1/1/2005 --- 1
1/16/2005 --- 3
2/28/2005 --- 2

It's means on the particular date, there are /is how many ppl logged in to the system? Can it be done in SQL(MS SQL 2000) or i have to use ASP to display it?

Thanks

Roelf
04-11-2005, 10:46 AM
you should group by a calculated column in your query where the datefield is shortened to just the date-part,

like:

SELECT COUNT(name) as Total, CONVERT(varchar, logDateTime, 101) AS logDate
FROM yourTable
GROUP BY CONVERT(varchar, logDateTime, 101)