Retrieve records from sqlserver 2005 which are today inserted
-
Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance
-
Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance
- I hope you're using a DATETIME field and not storing dates as strings. Otherwise you're hosed. 1) If this is a recent version of SQL Server you can try
WHERE datefield >= CAST(GETDATE() AS DATE)
- I hope you're using a DATETIME field and not storing dates as strings. Otherwise you're hosed. 1) If this is a recent version of SQL Server you can try
-
Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance
-
i have found it :) WHERE LASTUPDATEON >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) AND LASTUPDATEON < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1)
WTE! :wtf: Which database system? Why would you have to eliminate records that will be updated tomorrow? "Simplify. Simpify." -- Thoreau
-
Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance
try this select * from booking where Convert(varchar(20),SaveDate,111)=Convert(varchar(20),GETDATE(),111) here savedate is the column where i need to check.
-
try this select * from booking where Convert(varchar(20),SaveDate,111)=Convert(varchar(20),GETDATE(),111) here savedate is the column where i need to check.
That is very very bad. Highly inefficient. You convert every (millions?)
SaveDate
value and then do a string compare -- which is much less efficient than the DATETIME compare would be. <anecdote> I once fixed a program that was written that way -- before I fixed it it took forty minutes to run, afterward it took only ten minutes. </anecdote> DON'T EVER DO THAT!! :mad: :mad: :mad: :mad: :mad: :mad: