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 |
ismailm
Starting Member
13 Posts |
Posted - 2012-08-10 : 05:05:44
|
Hi guys,Please can you help with the below...I am not getting a result. I need to search by the date AND time as there can be more than one time on the same day.select * from [TABLE]where [COLUMN WITH DATETIME VALUES] = '06-Jun-2012 12:52:07'Many thanks! |
|
ismailm
Starting Member
13 Posts |
Posted - 2012-08-10 : 05:08:19
|
Btw, I don't want to have to use between '06-Jun-2012 12:52:06' and '06-Jun-2012 12:52:08' if possible. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-08-10 : 05:18:32
|
what is the data type of that column ?and what is the issue with using the between ? KH[spoiler]Time is always against us[/spoiler] |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-08-10 : 05:49:35
|
there will be no issue with BETWEEN for that search as long as the column is a datetime.You'll even be able to use an index if it is.I'd advise using ISO strings though:WHERE [Column] BETWEEN '2010-06-06T12:52:06' AND '2010-06-06T12:52:08' Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
|
|
ismailm
Starting Member
13 Posts |
Posted - 2012-08-10 : 06:28:13
|
quote: Originally posted by khtan what is the data type of that column ?and what is the issue with using the between ? KH[spoiler]Time is always against us[/spoiler]
data type datetime.i have a number of values to query and it is a pain to use between. if there is a way of doing it without between it would be best. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-10 : 06:51:17
|
If you are trying to select the rows that fall within a certain time range, you can use a query such as shown below. This selects all the rows for June 6 2012 (from 12:00 AM upto but not including 12:00 AM on the 7th).select * from [TABLE]where [COLUMN WITH DATETIME VALUES] >= '20120606'AND [COLUMN WITH DATETIME VALUES] < '20120607' |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-08-10 : 06:54:18
|
and if you have a number of ranges then put them into a table variable and JOIN on the BETWEEN (or greater than less than syntax)Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
|
|
|
|
|