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 |
|
newty25
Starting Member
21 Posts |
Posted - 2002-07-31 : 12:18:06
|
I'm writing a SQL query and using the group by statement to get a count on a datetime field. The problem is that I need the time from 0800 AM one day to the next day. So, the query should be simple... so far it looks likeSELECT DATEPART(D, UPDATE_TIME), COUNT(*) FROM MYTABLE GROUP BY DATEPART(D, UPDATE_TIME) The group by will work... but I need to redefine the datepart function to yeild the correct day parameters. Should I use a subquery within the first datepart... or is there another function that SQL provides other than datepart that I could use?Thanks in advance!newty25<edit>to fix display problem</edit>Edited by - robvolk on 07/31/2002 12:25:46 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-07-31 : 12:28:17
|
| SELECT DATEPART(D, DateAdd(hour, -8, UPDATE_TIME)), COUNT(*) FROM MYTABLE GROUP BY DATEPART(D, DateAdd(hour, -8, UPDATE_TIME))That subtracts 8 hours from the update time to match the date boundary you want. |
 |
|
|
newty25
Starting Member
21 Posts |
Posted - 2002-07-31 : 13:08:07
|
| thanks, robvolk!Works great!newty25 |
 |
|
|
|
|
|