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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-02-24 : 08:54:57
|
| George writes "MS Server 2000SQL 7 SP4 We have two tablesMySystem.ReservationsMySystem.ClientsThe two tables are related by Client_IDThe problem is to determine which clients had reservation in 2004, MySystem.Reservations.ReservationOpenDate BETWEEN '2004-01-01' AND '2004-12-31'and did not return in 2005,MySystem.Reservations.ReservationOpenDate NOT BETWEEN '2005-01-01' AND '2005-12-31'However NOT BETWEEN includes clients who made reservations in 2003 and 2006Is it possible with this version of SQL Server to find data NOT in a set?" |
|
|
coolerbob
Aged Yak Warrior
841 Posts |
Posted - 2006-02-24 : 12:21:59
|
| Yes,Select R.IDfrom Reservations R join Clients C on C.Client_ID=R.Client_IDwhere (R.ReservationOpenDate NOT BETWEEN '2005-01-01' AND '2005-12-31') ANDR.ID in (Select T.IDfrom Reservations T join Clients C on C.Client_ID=T.Client_IDwhere T.ReservationOpenDate BETWEEN '2004-01-01' AND '2004-12-31')That's the best I can do without DDL/DML. But you get the idea I hope. |
 |
|
|
|
|
|