September 15, 2009 at 1:13 pm
Below is my query and here's the issue: if I enter a start date of 3/19/09 and an end date of 3/20/09, I return the correct record for 3/19/09. However if I change my end date to 3/19/09, I don't retrieve any results???
@pDocTypeCHAR(1000),
@pDateStartDATETIME,
@pDateEndDATETIME
AS
SET NOCOUNT ON
SELECT
CONVERT(VARCHAR(10), createdatetime, 101)
AS CreateDateTime,
DocType,
Pagecount
FROM UsingView
WHERE
CreateDateTime >= @pDateStart
AND CreateDateTime <= @pDateEnd
September 15, 2009 at 1:16 pm
In SQL, dates are considered midnight if they don't have a time assigned to them. Thus, what you're looking for are rows that are in between midnight on the 19th and midnight on the 19th. In other words, all you'd get with that are rows that have exactly midnight on the 19th.
Try adding one day and using less-than.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
September 15, 2009 at 1:17 pm
The datetime datatype will use midnight as the time if none is specified. So you really do want the dates between 03/19 and 03/20
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply