Animal Entry Reasons by Species and Date
###
Auditing
###
Any rev03
###
Number of animals of each species who entered the shelter for each entry category.
###
en
###
$VAR from DATE Enter from date$
$VAR to DATE Enter to date$

SELECT COUNT(a.ID) AS TotalEntry, e.ReasonName, s.SpeciesName
FROM animal a
INNER JOIN species s ON s.ID = a.SpeciesID
INNER JOIN entryreason e ON e.ID = a.EntryReasonID
WHERE 
DateBroughtIn >= '$@from$' AND DateBroughtIn <= '$@to$' AND NonShelterAnimal = 0
GROUP BY s.SpeciesName, e.ReasonName
UNION SELECT COUNT (*) AS TotalEntry, e.ReasonName, s.SpeciesName 
FROM adoption m
INNER JOIN animal a ON a.ID = m.AnimalID
INNER JOIN species s ON s.ID = a.SpeciesID
INNER JOIN entryreason e ON e.ID = m.ReturnedReasonID
WHERE ReturnDate >= '$@from$' AND ReturnDate <= '$@to$'
GROUP BY s.SpeciesName, e.ReasonName
ORDER BY SpeciesName, ReasonName
###
$$HEADER
HEADER$$

$$GROUP_SpeciesName
$$HEAD
<h2>$SPECIESNAME</h2>
<table border="0">
$$FOOT
<tr>
<td><b>Total for $SpeciesName:</b></td> <td><b>{SUM.TOTALENTRY.0}</b></td>
</tr>
</table>
GROUP$$

$$BODY
<tr>
<td>$REASONNAME:</td>
<td>$TOTALENTRY</td>
</tr>
BODY$$

$$FOOTER
FOOTER$$


