Dear All
create table Pole (Poleid int,Position decimal(5,2))
create table Distance (Did int,FromPosition decimal(5,2), ToPosition decimal(5,2),ReprotNo varchar(10)
,DateOfReport datetime,Activity int)
Distance table brings data from few tables , it keeps reports of actities of poles
insert into Distance (FromPosition,ToPosition,ReprotNo,DateOfReport,Activity)
select FromPosition,ToPosition,ReprotNo,DateOfReport,a.Activity
from a
join b on a.aid=b.aid and b.cat=0
union
select b.f as FromPosition,b.t as ToPosition,ReprotNo,DateOfReport,a.Activity
from a
join b1 b on a.aid=b.aid and b.cat=1
Then i have to create following table PoleReport to get the latest report of a poleid from distance table
create PoleReport( PoleId int,ReprotNo varchar(500))
insert into PoleReport (Poleid , ReprotNo)
SELECT P.Poleid , D.ReprotNo
FROM
Pole P
JOIN
Distance D ON P.Position BETWEEN D.FromPosition AND D.ToPosition
WHERE
D.Did = ( SELECT TOP 1 D1.Did FROM
Pole P1
JOIN Distance D1 ON P.Position BETWEEN D1.FromPosition AND D1.ToPosition
ORDER BY D1.DateOfReport )
Q1) Please tel me is it possible that the PoleReport gets created auto matically using indexed view as an when entry is done .
Because above query takes good time, so i have to run it at afternoon or at night, when no body is seeing reports.
yours sincerely