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 |
|
vinaym
Starting Member
8 Posts |
Posted - 2011-10-03 : 09:05:48
|
| I have an ID field two date fields in table named as From_Date and To_Date. I want to select this dates with date criteria.ID From_Date To_Date1 2011-05-03 2011-05-282 2011-04-29 2011-05-103 2011-05-09 2011-05-204 2011-04-28 2011-05-095 2011-04-29 2011-05-196 2011-05-09 2011-05-097 2011-05-09 2011-05-098 2011-05-09 2011-05-099 2011-05-21 2011-05-2110 2011-06-06 2011-06-0611 2011-05-21 2011-05-2812 2011-05-14 2011-05-2813 2011-05-23 2011-05-2414 2011-05-27 2011-05-2715 2011-05-23 2011-05-24Now I want two parameter for condition of start date and end date like@StartDate = '05/01/2011'@EndDate = '05/10/2011'And I want Output from these parameters when ever array of dates between startdate and enddate parameter should be compare to array of dates between From_Date and To_Date fieldOutput:ID From_Date To_Date1 2011-05-03 2011-05-182 2011-04-29 2011-05-103 2011-05-09 2011-05-204 2011-04-28 2011-05-095 2011-04-29 2011-05-196 2011-05-09 2011-05-097 2011-05-09 2011-05-098 2011-05-09 2011-05-09is this possible in single query instead use of trigger or function? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-03 : 09:09:49
|
| [code]SELECT ID,From_date,To_dateFROM TableWHERE From_Date >=@StartDate AND To_Date<=@EndDate[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vinaym
Starting Member
8 Posts |
Posted - 2011-10-03 : 09:25:03
|
| But using this simple condition couldn't get all related rows. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-10-03 : 09:26:29
|
SELECT ID, From_date, To_dateFROM TableWHERE From_Date <= @EndDate AND To_Date>= @StartDate N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|