Thanks for the response.
I am posting the project's code to put in in a better context.
I would mention that the project as an overview consists of callboxes
(road side) that call in and post alarms. Those callboxes are located
in different counties so the report needs to total how many alarms per
county and how many alarms per call box in a date range
My objective again is to get a count of two groups in the select as
they are selected:
1) The first group (or outer group) are all alarm records for each
county.
2) The second group (or inner group) are all the records for a
specific call box.
Here is the actual code : (Slice from a stored procedure ....
@Project_ID , @Start_Date, and @End_Date are input parameters)
SELECT
C.Callbox_ID,
C.Sign_Number,
C.Ani,
C.Highway,
C.LastPrevMaintDate,
CY.County,
AL.Alarm_Log_ID,
AL.Project_ID,
AL.Alarm_DT,
AL.Created_DT,
AL.Last_Called_In_Date,
AL.Scheduled_Call_In_Date,
AL.Alarm_Source
{ something like ..
Count(
FROM Callbox C (NOLOCK),
County CY (NOLOCK),
Alarm_Log AL (NOLOCK)
WHERE AL.Project_ID = @Project_ID
AND AL.Alarm_DT BETWEEN (@Start_Date) AND (@End_Date)
AND C.ANI = AL.ANI
AND AL.Alarm_Source = 'E'
AND CY.County_ID =* C.County_ID
GROUP BY CY.County,
C.Sign_Number,
C.Callbox_ID,
C.Ani,
C.Highway,
C.LastPrevMaintDate,
AL.Alarm_DT,
AL.Created_DT,
AL.Last_Called_In_Date,
AL.Scheduled_Call_In_Date,
AL.Alarm_Source,
AL.Project_ID,
AL.Alarm_Log_ID
ORDER BY CY.County, C.Sign_Number
You get a unique key as a composite of two columns using the Alarm_Log
table and the Callbox with the Project_ID and ANI.
To Wayne's point, to complicate it more here there are some records
where County_ID is NULL.
I have resorted to the temp table approach and iterating through it to
update these values in new columns. It is not working out to smotthly
right now because of an error that the code is "returning more that
one value in a subquery".
This whole format I believe is a "cross tab" report. The result will
be using Quick Reports 3.0 and the TQRGrouping functionality to
display it. The basic grouping is displaying right, all I need are
these totals ..
Thanks
--
Reid Roman
Future Generation Software
http://www.futuregenerationsoftware.com