Experts!
I've been having a bit of a problem....
I have data on a compressor in two tables. One table contains the % load that the compressor is under as integer and the other table tells me when the compressor is turned on as a boolean.
I want to know what the average level of load is during the time the compressor is on.
CREATE PROCEDURE dbo.PenFridgeSumRun
(
@BeginDateID As datetime = 0,
@EnddateID As datetime = 0,
@Tagname As varchar(250),
@RunTagname As varchar(250),
@Avg As float output
)
AS
BEGIN
SELECT @Avg = AVG (ISNULL(AH.Value, 0))
FROM AnalogHistory AH
LEFT JOIN DiscreteHistory DH ON DH.TagName = @RunTagname
WHERE AH.datetime BETWEEN @BeginDateID AND @EndDateID
AND DH.Value = 1
END
I pass the data for the date and or variable from another SP.
Exec [PenFridgeNew] '14 Mar 2006 08:00:00', '21 Mar 2006 08:00:00' 'Gis_Pen_Container_Mycom_Run_Pen', 'Gis_Pen_Container_Mycom_Run', @avg output
I currently get zero's back for the Average.
Any ideas??
Cheers
Lee
I've been having a bit of a problem....
I have data on a compressor in two tables. One table contains the % load that the compressor is under as integer and the other table tells me when the compressor is turned on as a boolean.
I want to know what the average level of load is during the time the compressor is on.
CREATE PROCEDURE dbo.PenFridgeSumRun
(
@BeginDateID As datetime = 0,
@EnddateID As datetime = 0,
@Tagname As varchar(250),
@RunTagname As varchar(250),
@Avg As float output
)
AS
BEGIN
SELECT @Avg = AVG (ISNULL(AH.Value, 0))
FROM AnalogHistory AH
LEFT JOIN DiscreteHistory DH ON DH.TagName = @RunTagname
WHERE AH.datetime BETWEEN @BeginDateID AND @EndDateID
AND DH.Value = 1
END
I pass the data for the date and or variable from another SP.
Exec [PenFridgeNew] '14 Mar 2006 08:00:00', '21 Mar 2006 08:00:00' 'Gis_Pen_Container_Mycom_Run_Pen', 'Gis_Pen_Container_Mycom_Run', @avg output
I currently get zero's back for the Average.
Any ideas??
Cheers
Lee