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.
Author |
Topic |
bnd_ck
Starting Member
4 Posts |
Posted - 2014-07-15 : 08:35:49
|
I have a table has following fields(Process, datestart,dateend,datedue,,,,)Process datestart dateend ...A 14.07.2017 20.07.2014B 15.07.2014 21.07.2014C 24.07.2014 30.07.2014what i want when user enters from date and end date. i want to filter records which are fallen between those two input dates.if user enters 17.07.2014 and 20.07.2014 as input range. query should show only A and B process asA 14.07.2017 20.07.2014B 15.07.2014 21.07.2014qiuck help plzz |
|
MichaelJSQL
Constraint Violating Yak Guru
252 Posts |
Posted - 2014-07-15 : 09:41:01
|
CREATE TABLE #Dates(ID INT identity(1,1),Process varchar(5),datestart date,dateend date)INSERT INTO #DatesVALUES('A','07/14/2014','07/20/2014'),('B','07/15/2014','07/21/2014'),('C','07/24/2014','07/30/2014')DECLARE @start date = '7/15/2014'DECLARE @end date = '7/20/2014'-- any that falls in range -- i think this is what you are describing. this is either the end or the start is occurring between the periods enteredSELECT * FROM #DatesWHERE @start between datestart AND dateend AND @end between datestart AND dateend |
|
|
bnd_ck
Starting Member
4 Posts |
Posted - 2014-07-15 : 10:02:45
|
thanksyou mean stored procedure ?how about where clause in sql for this situation? if user enters random 2 dates as input. |
|
|
MichaelJSQL
Constraint Violating Yak Guru
252 Posts |
Posted - 2014-07-15 : 17:36:15
|
You can turn that into a procedure . You would probably want to protect against end date being before start date. you could also so tighten up the date logic so that the dates are exact or that the start date is in the range, but the end date is firm: meaning nothing that ends after the parameter regardless if it starts in the range - it all depends on what you are trying to do. |
|
|
|
|
|
|
|