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 |
|
KabirPatel
Yak Posting Veteran
54 Posts |
Posted - 2010-06-10 : 05:27:57
|
| Hi,I have a table as follows:ID StartDate EndDate--------------------------------1 1 May 2010 10 Aug 20102 11 Jun 2010 10 Sep 20103 1 May 2010 31 May 20104 1 Aug 2010 31 Aug 2010etc......I would like a query that would return all records where at least one day between the start_date and end_date fall in June.i.e. in the above ID's 1 and 2 should be returned as June dates lie between the start and end dates.I tried a basic query as follows:select sum(volume)from [myTable]where startdate >= '1 June 2010'and enddate < '1 July 2010'but this didnt seem to work.Thanks |
|
|
malpashaa
Constraint Violating Yak Guru
264 Posts |
Posted - 2010-06-10 : 06:01:51
|
Try this:SELECT SUM(volume) FROM [myTable] WHERE (startdate >= '20100601' AND startdate < '20100701') OR (enddate >= '20100601' AND enddate < '20100701') |
 |
|
|
|
|
|