This is all "Air code" and might be horribly wrong. Unmatched brackets are
my "thing" so I prefer to paste tested code.
from query 4, working back, we want as a result:
SELECT tblLocation.LocationName,tblParameter.ParameterName, _
So we want:-
GROUP BY tblLocation.LocationName,tblParameter.ParameterName
at the end.
---------------
and complete our desired results in SELECT :-
COUNT(tblResults.ResultValue) AS Total, _
SUM(IIF (tblResults.ResultIsPass = "0",1,0)) AS Failed, _
SUM(IIF(tblResults.ResultIsPass = "0",0, 1)) AS Passed, _
1 + avg(tblResults.ResultIsPass = "0") AS Percent
--------------
Putting it all together:-
SELECT tblLocation.LocationName,tblParameter.ParameterName,
COUNT(tblResults.ResultValue) AS Total,
SUM(IIF(tblResults.ResultIsPass = "0",1,0)) AS Failed,
SUM(IIF(tblResults.ResultIsPass = "0",0, 1)) AS Passed,
1 + avg(tblResults.ResultIsPass = "0") AS Percent
FROM (tblParameter INNER JOIN (tblSite INNER JOIN (tblSample INNER JOIN
tblResults ON tblSample.SampleID = tblResults.SampleID) ON
tblSite.SiteID = tblSample.SiteID) ON tblParameter.ParameterID =
tblResults.ParameterID)
INNER JOIN tblLocation ON tblSite.LocationID = tblLocation.LocationID
GROUP BY tblLocation.LocationName,tblParameter.ParameterName ;
It will be a minor miracle if I have got that syntax right, and if I have
not it will demonstrate my point about maintenance of complex SQL.
anil said:
Dear david
My queries look like (although not syntaxically correct, just an idea)
Query 1: - SELECT tblLocation.LocationName, tblSample.SampleTakenDate,
tblParameter.ParameterName, tblResults.ResultValue,
tblResults.ResultIsPass
FROM (tblParameter INNER JOIN (tblSite INNER JOIN (tblSample INNER JOIN
tblResults ON tblSample.SampleID = tblResults.SampleID) ON
tblSite.SiteID = tblSample.SiteID) ON tblParameter.ParameterID =
tblResults.ParameterID) INNER JOIN tblLocation ON tblSite.LocationID =
tblLocation.LocationID;
Query 2(Q2) : - Select locationName,parameterName,Count(resultValue) as
Total,SampleTakenDate from query1;
Query 3(Q3): - Select locationName,parameterName,Count(resultValue) as
failed,SampletakenDate from query1 where query1.resultispass = "0";
Query 4: - Select Q2.LocationName,Q2.ParameterName,Q2.Total,Q3.Failed
,[Total]-[Fail] as [pass],[Pass]/[Total] as [Percent] from q2,q3 joined
by locationName and ParameterName
So if you help me now as in your last mail I could not judge properly
what to do .
thanks
anil