Selecting date range
-
I need some help with a stored procedure, I have a table in my database that I am writing records to, specifically a BeginningDate field and EndingDate field. I want to be able to run a stored procedure that selects records based on a range of dates. This range of dates begins with monday and ends the following sunday, it covers an entire week. When I run the stored proc the where clause goes something like this:
select UserID, BeginningDate, EndingDate, From tableName where UserID = @UserID and BeginningDate >= @BeginDate and EndingDate <= @EndDate
I know that it will not return any records if there is a date that is less than the EndDate. My question is how can I adjust this so it selects the one record based on a BeginDate and EndDate parameters? -
I need some help with a stored procedure, I have a table in my database that I am writing records to, specifically a BeginningDate field and EndingDate field. I want to be able to run a stored procedure that selects records based on a range of dates. This range of dates begins with monday and ends the following sunday, it covers an entire week. When I run the stored proc the where clause goes something like this:
select UserID, BeginningDate, EndingDate, From tableName where UserID = @UserID and BeginningDate >= @BeginDate and EndingDate <= @EndDate
I know that it will not return any records if there is a date that is less than the EndDate. My question is how can I adjust this so it selects the one record based on a BeginDate and EndDate parameters?select UserID, BeginningDate, EndingDate, From tableName where UserID = @UserID and ((BeginningDate >= @BeginDate and EndingDate <= @EndDate) OR (BeginningDate >= @BeginDate) OR (EndingDate <= @EndDate)) Hope thats what you want ?
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder