I have a DB that handles reservations made against resources. I'm using SSRS 2008 r2
. I've made sure that all joins in visual designer are showing all rows on RESOURCES
table.
How can I return all rows from the RESOURCES
table regardless of data in other joining tables? I'm using a WHERE
clause with parameters of start date and end date. These parameters refer to dates on the reservations
table. If I remove this from the WHERE
clause I get all RESOURCES
. However I need the start date and end date to be included so that I can search between two dates. I thought that if I did left outer join on resources
table I'd get all resources. However, only getting resources with associated reservations made between start date and end date.
What am I doing wrong?
SELECT
(rows here)
FROM
_ReservationsAttributes
RIGHT OUTER JOIN
_Reservations ON _ReservationsAttributes.ReservationId = _Reservations.ReservationId
RIGHT OUTER JOIN
_Resources ON _Reservations.ResourceId = _Resources.ResourceId
LEFT OUTER JOIN
_LocationsAttributes ON _Resources.LocationId = _LocationsAttributes.LocationId
LEFT OUTER JOIN
_Locations ON _Resources.LocationId = _Locations.LocationId
LEFT OUTER JOIN
_ResourcesAttributes ON _Resources.ResourceId = _ResourcesAttributes.ResourceId
WHERE
(_LocationsAttributes.[@33] = @Distinct_Premise) AND
(_Reservations.StartDate >= @Start_Date) AND
(_Reservations.EndDate <= DATEADD(DAY, 1, @End_Date))
ORDER BY
_Locations.OrderBy,
_Resources.Name
Deconstruct your query. Start with only the central table (_Resources). Add each of the other tables in one at a time, with the WHERE
conditions. Make sure each step makes sense before adding the next table in.
My guess - you are getting confused by using both LEFT OUTER
and RIGHT OUTER
joins. We would need the schema to be sure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.