MCTampa
Board Regular
- Joined
- Apr 14, 2016
- Messages
- 97
In my database, I have two tables: Inventory and Restrictions.
The inventory is a list of hotels, grouped by developer, for specific unit sizes and check in dates.
On the table table called Restrictions I can manually enter the variables I want restricted. I'm not sure if I want to delete them or isolate them in a different table, so for now, I'm just working on the Select query.
There is a hierarchy to my restrictions.
1 - Developer
2 - Area
3 - Resort
4 - Size
The four items above are all optional and can be left blank.
5 - Start Week (SW)
6 - End Week (EW)
Items 5 and 6 are mandatory and must be included.
If I specify the Developer, I want all associated items to be returned based on the SW and EW parameters.
If I leave Developer blank, and specify Area, i I want all associated items to be returned based on SW and EW.
If I leave Developer and Area blank, and specify Resort, i I want all associated items to be returned based on SW and EW.
If I leave Developer and Area and Resort blank, and specify Size, i I want all associated items to be returned based on SW and EW.
Below is my code, which works fine if I specify all items, but not if I leave one blank.
The reason for leaving one blank is because (for example) there are numerous resorts in an area, or numerous resorts associated to a developer.
I'm sure there has to be an Or somewhere, but when I've tried that, my data gets inflated.
Thanks for any help,
Mike
The inventory is a list of hotels, grouped by developer, for specific unit sizes and check in dates.
On the table table called Restrictions I can manually enter the variables I want restricted. I'm not sure if I want to delete them or isolate them in a different table, so for now, I'm just working on the Select query.
There is a hierarchy to my restrictions.
1 - Developer
2 - Area
3 - Resort
4 - Size
The four items above are all optional and can be left blank.
5 - Start Week (SW)
6 - End Week (EW)
Items 5 and 6 are mandatory and must be included.
If I specify the Developer, I want all associated items to be returned based on the SW and EW parameters.
If I leave Developer blank, and specify Area, i I want all associated items to be returned based on SW and EW.
If I leave Developer and Area blank, and specify Resort, i I want all associated items to be returned based on SW and EW.
If I leave Developer and Area and Resort blank, and specify Size, i I want all associated items to be returned based on SW and EW.
Below is my code, which works fine if I specify all items, but not if I leave one blank.
The reason for leaving one blank is because (for example) there are numerous resorts in an area, or numerous resorts associated to a developer.
I'm sure there has to be an Or somewhere, but when I've tried that, my data gets inflated.
SQL:
SELECT
restrictions.AREA,
restrictions.Developer,
restrictions.[SW],
restrictions.[EW],
ic.RESX,
ic.TRKFLD,
ic.Size,
Sum(ic.[Units]) AS Units
FROM Restrictions AS restrictions LEFT JOIN Inventory AS ic ON
(restrictions.Area = ic.Area)
And(restrictions.Developer = ic.Developer)
AND (restrictions.Resort = ic.resx)
AND (ic.Week >= restrictions.[SW])
AND (ic.Week <= restrictions.[EW])
WHERE (((ic.[Units]) Is Not Null))
GROUP BY restrictions.AREA, restrictions.Developer, ic.RESX, ic.TRKFLD, ic.SpaceType, ic.Size, restrictions.[SW], restrictions.[EW];
Thanks for any help,
Mike