Apologies for the somewhat confusing title. It's difficult to summarise the issue in a couple of words. I am making a request to a database, on the following tables:
Event
:
ID, startdate, offtime, meetingid reason
Meeting
:
ID, description
cm_delay_reasons
:
ID, reasoncode, reasondescription
The tuples returned need to match the following criteria:
- The
MeetingID
inEvent
needs to map to anID
inMeeting
. - The
reason
value inEvent
can not be null - The
reason
value inEvent
can map to areasoncode
incm_delay_reasons
.- The
reason
value can also not map, but must not be null. - If it isn't null, then don't display a reason description.
- The
The reason is for the latter part is simple. Event.Reason
can either be a code, indicating it matches one of our preconfigured delays for an event. It can also be plaintext, indicating that the user decided their own reason for a delay. The aim is to get both of these, and for those values that do not map, leave the reason description empty.
The SQL query I have come up with is:
select
m.description, e.startdate, e.offtime, e.reason, d.reasondescription
from
event e, meeting m, cm_delay_reasons d
where
e.meetingid = m.id
and (d.reasoncode = e.reason);
However, ths isn't displaying the custom reasons that a user can put in. Only the predefined ones that exist in the cm_delay_reasons
table, so I changed my tact and attempted:
select
m.description, e.startdate, e.offtime, e.reason, d.reasondescription
from
event e, meeting m, cm_delay_reasons d
where
e.meetingid = m.id
and (e.reason is not null);
However this is causing duplicates. What I need to work out is how to marry the functionality of the two.