Click here to Skip to main content
15,920,031 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Dotnet Geeks,

I need to select only a single date from a huge data of around five months.
I have written a stored procedure for the same and now i want to retrieve a single date from that; since i will be getting timeout exception while accessing that stored procedure retreiving huge data.

Just i need to put a condition in query like
C.log_date= '2012-03-02'


if you don't understand please go through SP and see C.log_date there.
Please give me that small condition where i can get a particular date

SQL
create PROCEDURE [dbo].[Get_op_meter_data]
  	@Point_location VARCHAR(50),
	@sw_name VARCHAR(30),
	@p_equip_id CHAR(10),
	@equip_id CHAR(10),	
	@source_type_id CHAR(10),
	@log_date date
AS
Declare @log_time varchar(20),@ASE_Reading numeric,@G_Reading numeric
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 A.equip_id = B.equip_id

And C.log_date= '2012-03-02'


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 SW.sw_id=S.sw_id
AND   B.point_location = C.point_Location
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 A.equip_id = B.equip_id
AND SW.sw_id=S.sw_id
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_location = C.point_Location
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

Declare @TempTableVariable TABLE
(
Point_location  VARCHAR(50),
sw_name VARCHAR(30), 
p_equip_id CHAR(10), 
equip_id CHAR(10),
log_date datetime,
log_time datetime, 
ASE_Reading  numeric, 
G_Reading  numeric
)
Begin
insert into @TempTableVariable(Point_location,sw_name,p_equip_id,equip_id,log_date,log_time,ASE_Reading,G_Reading) 
values(@Point_location,@sw_name,@p_equip_id,@equip_id,@log_date,@log_time,@ASE_Reading,@G_Reading)
	End
Posted
Updated 17-Jun-12 3:06am
v2

Change the CommandTimeout property of your connection.

Best wishes,
Pablo.
 
Share this answer
 
you're asking your SP to do an awful lot of work ... perhaps there might be more mileage in creating another table, populated by trigger, which creates more useable values?

This has indices and inner join written all over it
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900