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 |
|
NeilC
Yak Posting Veteran
55 Posts |
Posted - 2008-09-16 : 16:16:59
|
I cave an events table there with StartTime as 2008-09-16 10:00:00 (SmallDateTime) and I wasnt to write a query to list all the events for a particular day. I'll need two queries to seperate AM and PM because they will be bound to a .net repeater.I thought I could just do:Select * from Events where StartTime = '2008-09-16' and datename(hour, StartTime) < 13 but it is not returning data because of the time in the small date time.Any Ideas? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-09-16 : 16:30:54
|
| I don't understand why you need two queries.Select * from Events where StartTime >= '2008-09-16' and StartTime < '2008-09-17'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
NeilC
Yak Posting Veteran
55 Posts |
Posted - 2008-09-16 : 16:34:50
|
| One returning AM events and one returning PM events - your query returns everything regardless of AM or PM |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-16 : 22:19:17
|
obviously your column StartTime contains date & time so "StartTime = '2008-09-16'" will not return anythingDon't understand why do you need 2 query, but here it isAM querySelect * from Events where StartTime >= '2008-09-16' and StartTime < '2008-09-16 13:00:00' PM querySelect * from Events where StartTime >= '2008-09-16 13:00:00' and StartTime < '2008-09-17' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-09-17 : 02:28:44
|
quote: Originally posted by khtan obviously your column StartTime contains date & time so "StartTime = '2008-09-16'" will not return anythingDon't understand why do you need 2 query, but here it isAM querySelect * from Events where StartTime >= '2008-09-16' and StartTime < '2008-09-16 13:00:00' PM querySelect * from Events where StartTime >= '2008-09-16 13:00:00' and StartTime < '2008-09-17' KH[spoiler]Time is always against us[/spoiler]
That should beAM querySelect * from Events where StartTime >= '2008-09-16' and StartTime < '2008-09-16 12:00:00'PM querySelect * from Events where StartTime >= '2008-09-16 12:00:00' and StartTime < '2008-09-17'MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-17 : 02:36:00
|
I just following OP's definition of AM < 13 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|