I have a stored procedure :-
CREATE procedure St_Proc_GetTimeEntryID
@userID int,
@timeEntryID int output
as begin
set nocount on;
SET @timeEntryID=0
DECLARE @TEMP INT
SET @TEMP=0
SELECT @TEMP=ProductionTimeEntryID
FROM production
WHERE ProductionTimeEntryID =
(SELECT MAX(ProductionTimeEntryID)
FROM production
where UserID=@userID
and (CalendarDate = (select GETDATE()))
and IsTaskCompleted=1 )
BEGIN
SET @timeEntryID=@TEMP
END
END
Here CalendarDate is column which containing Date As 06/26/201212:00PM format .
I want to compare the date part only with system date part (06/26/2012 = 06/26/2012) in my subquery which is
(SELECT MAX(ProductionTimeEntryID)
FROM production
where UserID=@userID
and (CalendarDate = (select GETDATE()))
and IsTaskCompleted=1 )
Please guide me what modification i ll do to get the result.
The most efficient method (meaning fully able to utilize an index on
CalendarDate, if one exists) is going to be, on SQL Server 2000/2005:If using SQL Server 2008+:
You can also use a direct cast in SQL Server 2008+, but I’m not 100% sure this is guaranteed to use an index on
CalendarDatein all scenarios:Because this casting does not work with other date/time data types, for consistency I much prefer the open-ended range technique, and definitely do not condone most of the scenarios where you perform implicit or explicit conversions on the column (since this usually means an index won’t be used). I’ve ranted about this and several other date/time atrocities plenty at the following blog posts:
What do BETWEEN and the devil have in common?
Bad habits to kick : mis-handling date / range queries