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 |
|
Shilpa22
Starting Member
37 Posts |
Posted - 2009-04-27 : 02:23:42
|
| Hello all,I need to retrieve today records.For example time field has the value 2009-04-27 05:57:47.320.. so i need to retireve all the records which fall in 2009-04-27.I am unable to get the exact query, pls help meThanks in advance.Thanks in AdvanceShilpa |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-27 : 02:25:00
|
[code]DECLARE @Today DATETIMESET @Today = DATEDIFF(DAY, 0, GETDATE())SELECT *FROM Table1WHERE Col1 >= @Today AND Col1 < DATEADD(DAY, 1, @Today)[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
Shilpa22
Starting Member
37 Posts |
Posted - 2009-04-27 : 02:42:23
|
| Thanks all,I got the query..its working..Select * from table_name Where Convert(varchar(12),column_name,101) = Convert(varchar(12),getdate(),101)Thanks in AdvanceShilpa |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-27 : 02:43:22
|
Yes it is!And then compare the speed between the two suggestions. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-27 : 02:55:16
|
quote: Originally posted by Shilpa22 Thanks all,I got the query..its working..Select * from table_name Where Convert(varchar(12),column_name,101) = Convert(varchar(12),getdate(),101)Thanks in AdvanceShilpa
Why do you convert dates to varchar and compare?Peso showed you a correct way of doing itMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|