Click to See Complete Forum and Search --> : Earliest datetime for each day. How?


chinnybloke
04-12-2006, 06:45 AM
Hello,

I have a table of user logon/logoff times. It only contains:
User ID
When they logged on
When they logged off
(logon/logoff times are DateTime in SQL Server 2005).

A user can logon and off several times during the day but I am trying to make a query that returns all first logons by each user for each day.

My query is basically:

SELECT WHO_SIGNED_ON, MIN(WHEN_SIGNED_ON) As Expr1
FROM LOGON_TABLE
GROUP BY WHO_SIGNED_ON

This returning the earliest logon by user, not the earliest for each day. How do I make it also group by just the date part of the DateTime column WHEN_SIGNED_ON?

I know this is bound to be relatively simple but I cannot see the wood for the trees!

Thanks in advance for any tips,
CB

chazzy
04-12-2006, 01:07 PM
i believe sql server has a date format function, what if you group by date_format(logon_datetime,'MM/DD/YYYY') ? that's more pseudo code as i'm not sure the exact syntax.