Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I am trying to create a statement to return all records where the "lst_maint_dt" field is equal to today (or basically any time today). I've tried the following:select item_nofrom im_itemwhere lst_maint_dt = DAY(GETDATE()) That obviously does not work. Any suggestions?
malpashaa
Constraint Violating Yak Guru
264 Posts
Posted - 2012-09-29 : 19:29:29
Try something like this:
SELECT item_no FROM im_item WHERE lst_maint_dt >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) AND lst_maint_dt < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 1)