gRegulator
Technical User
Hi, I have the following SQL query. For some reason, the results it produces are very wrong. What I am trying to do is get a count of the types of offences committed by people (grouped by male and female) for clients admitted during a given time period. My query looks like this:
And it is based upon the following query:
Does anyone have suggestions on why I may be getting incorrect answers from my query?
Any help is greatly appreciated!
Thanks,
Greg
Code:
PARAMETERS [Forms]![frm_dateparameter_q31]![txtStart] DateTime, [Forms]![frm_dateparameter_q31]![txtEnd] DateTime;
SELECT qry_q31_offence_types.Offence, -Sum([Male]) AS [Male Clients], -Sum([Female]) AS [Female Clients]
FROM qry_q31_offence_types
WHERE (((qry_q31_offence_types.Start) Between [Forms]![frm_dateparameter_q31]![txtStart] And [Forms]![frm_dateparameter_q31]![txtEnd]))
GROUP BY qry_q31_offence_types.Offence;
And it is based upon the following query:
Code:
SELECT 'Offence Against Person' AS Offence, Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Offence Against Person] = True
UNION SELECT 'Offence Against Property', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Offence Against Property] = True
UNION SELECT 'Impaired Driving', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Impaired Driving] = True
UNION SELECT 'Other Criminal Code', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Other CCC] = True;
UNION SELECT 'Drug Offence', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Drug Offence] = True
UNION SELECT 'Other Federal Statute', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Other Federal Statute] = True
UNION SELECT 'Liquor Offence', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Liquor Offence] = True
UNION SELECT 'Other Provincial Statute', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Other Provincial Statute] = True
UNION SELECT 'Municipal By-Law Offence', Male, Female, NZ([Probation Start],[CS Start]) as [Start], NZ([Probation Expiry],[CS Expiry]) as [End]
From tbl_offenders
WHERE [Municipal By-Law Offence] = True;
Does anyone have suggestions on why I may be getting incorrect answers from my query?
Any help is greatly appreciated!
Thanks,
Greg