I am developing an web based incident reporting system using ASP/VBScript which records incidents and remdial actions taken to remedy the incidents.
Each incident may have many actions associated with it. Each action may be associated with only one incident.
The schema of the incidents table goes "incidentID, description etc...".
The actions table goes "actionID, fkIncident, description, finnishDate". fkIncident is the foreign key for the incident table.
I am trying to write a list incidents page which will list all incidents but which also includes a column showing how many actions are currently associated with each incident and how many actions are finnished.
i.e.
incidentID| Description | Actions | Actions Completed
-----------------------------------------------------
1 |Lorem ipsum | 5 | 2
2 |Lorem ipsum | 4 | 0
3 |Lorem ipsum | 10 | 10
As you can see, the "actions" column should just be a count of all related records in the actions table and "actions completed" column should be a count of the same records where the finnishDate field is not null.
How can I write a query to return the results I want?
Each incident may have many actions associated with it. Each action may be associated with only one incident.
The schema of the incidents table goes "incidentID, description etc...".
The actions table goes "actionID, fkIncident, description, finnishDate". fkIncident is the foreign key for the incident table.
I am trying to write a list incidents page which will list all incidents but which also includes a column showing how many actions are currently associated with each incident and how many actions are finnished.
i.e.
incidentID| Description | Actions | Actions Completed
-----------------------------------------------------
1 |Lorem ipsum | 5 | 2
2 |Lorem ipsum | 4 | 0
3 |Lorem ipsum | 10 | 10
As you can see, the "actions" column should just be a count of all related records in the actions table and "actions completed" column should be a count of the same records where the finnishDate field is not null.
How can I write a query to return the results I want?