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 |
|
brianfitz
Starting Member
4 Posts |
Posted - 2011-07-05 : 10:02:22
|
Hi guys, hope you can help.Basically I'm attempting to create a query specifying a timeframe, from 1st june 2011 to 30th June 2011, between 12:00 and 14:00.I have half of it, in that I have created this:((tablename.datetime>{ts '2011-05-31 12:00:0'}) But all that does is show everything after 12pm. Now I know it's something simple I'm doing wrong but how do I get the query to terminate at 2pm?Many thanks,Brian |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-07-05 : 10:07:21
|
SELECT *FROM dbo.Table1WHERE [Datetime] >= '20110601 12:00:00' AND [Datetime] < '20110630 14:00'Or, just in case you only want 12:00 to 14:00 for each day,SELECT *FROM dbo.Table1WHERE [Datetime] >= '20110601 12:00:00' AND [Datetime] < '20110630 14:00'AND HOUR([Datetime]) >= 12 AND HOUR([Datetime]) < 14 N 56°04'39.26"E 12°55'05.63" |
 |
|
|
brianfitz
Starting Member
4 Posts |
Posted - 2011-07-05 : 10:28:05
|
| Absolutely perfect, thanks for your help mate. |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-07-05 : 14:33:03
|
| We have a DATE and a TIME data type nowSELECT .. FROM Foobar WHERE CAST(vague_timestamp AS DATE) BETWEEN '2011-06-01' AND '2011-06-30' AND CAST(vague_timestamp AS TIME) BETWEEN '12:00:00' AND '14:00:00' --CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
|
|
|