ALTER PROCEDURE [dbo].[Get_op_meter_data]
@Point_location VARCHAR(50),
@sw_name varchar(30),
@p_equip_id char(10),
@equip_id CHAR(10),
@Startdate datetime,
@EndDate datetime,
@source_type_id CHAR(10)
AS
Declare @log_time varchar(20),@log_date datetime,@ASE_Reading numeric,@G_Reading numeric
CREATE TABLE #tmp_tt_raw_meters1(Point_location VARCHAR(50), sw_name varchar(30), p_equip_id char(10), equip_id CHAR(10), log_date datetime, log_time VARCHAR(20), ASE_Reading numeric, G_Reading numeric)
select * into #tmp_tt_raw_meters1 from
(SELECT T.Point_location,T.sw_name, T.p_equip_id, T.equip_id, log_date, log_time, SUM(E_Reading) ASE_Reading , SUM(G_reading) AS G_Reading
FROM (
SELECT A.Point_location,SW.sw_name, A.p_equip_id, A.equip_id, CONVERT(DATE,C.log_date) AS log_date, CONVERT(VARCHAR(20), C.log_hrs)+ ':' + CONVERT(VARCHAR(20),C.log_min) AS log_time, C.Act_value AS E_Reading, 0 AS G_reading
FROM om_equipment A, om_equip_meter_map B, om_service_window SW, om_sw_location_map S, tt_raw_meter C
WHERE B.point_location = C.point_Location
AND A.equip_id = B.equip_id
AND SW.sw_id=S.sw_id
And C.log_date>= @Startdate
And C.log_date < @EndDate
AND CONVERT(VARCHAR(20), C.log_hrs)+ ':' + CONVERT(VARCHAR(20),C.log_min) = CONVERT(VARCHAR(20), s.start_hrs)+ ':' + CONVERT(VARCHAR(20),s.end_hrs)
AND B.point_device = C.point_device
AND B.functionblock = C.FunctionBlock
AND B.source_type_id = 'RAW_POW'
UNION
SELECT A.Point_location,SW.sw_name, A.p_equip_id, A.equip_id, CONVERT(DATE,C.log_date) AS log_date, CONVERT(VARCHAR(20), C.log_hrs)+ ':' + CONVERT(VARCHAR(20),C.log_min) AS log_time, 0 AS E_Reading, C.Act_value AS G_reading
FROM om_equipment A, om_equip_meter_map B, om_service_window SW, om_sw_location_map S, tt_raw_meter C
WHERE B.point_location = C.point_Location
AND A.equip_id = B.equip_id
AND SW.sw_id=S.sw_id
And C.log_date>= @Startdate
And C.log_date < @EndDate
AND CONVERT(VARCHAR(20), C.log_hrs)+ ':' + CONVERT(VARCHAR(20),C.log_min) = CONVERT(VARCHAR(20), s.start_hrs)+ ':' + CONVERT(VARCHAR(20),s.end_hrs)
AND B.point_device = C.point_device
AND B.functionblock = C.FunctionBlock
AND B.source_type_id = 'GAS') T
GROUP BY T.Point_location, T.sw_name, T.p_equip_id, T.equip_id, log_date, log_time
ORDER BY T.Point_location, T.sw_name, T.p_equip_id, T.equip_id, log_date, log_time
)
select * from #tmp_tt_raw_meters1 where Point_location=@Point_location and sw_name=@sw_name and p_equip_id=@p_equip_id and equip_id=@equip_id and (log_date < = @Startdate and > @EndDate) and ASE_Reading= @source_type_id and G_Reading= @source_type_id
drop table #tmp_tt_raw_meters1
I tried with this but its giving error again. I am not able to insert and retreive values using temporary tables also.