Only 2 indexes are created on the table :
CREATE INDEX [Ndx1_rtRefTitres] ON [dbo].[rtRefTitres]([rtCodeValeur], [rtDate]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [Ndx2_rtRefTitres] ON [dbo].[rtRefTitres]([rtDate])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
- Generate the table/View with DateMax ONLY for '2004%' :
Create View v_rtRefT_DateMax
As
select rtCodeValeur,DateMax=max(rtdate) from dbo.rtRefTitres
where rtCodeFival ='99999'
and rtDate like '2004%'
group by rtCodeValeur --order by 1
Then compare it with the original table :
select r.rtCodeValeur, rtLibelleValeur, rtcodeFival, DateMax
From rtRefTitres as r, v_rtRefT_DateMax as v
where r.rtCodeValeur = v.rtCodeValeur
and rtdate = DateMax
order by 1
- Generate another table/view with DateMax ony for year 2004
where rtCodeFival !='99999' :
Create view v_rtRefT_DateMax_DiffCdeFival
As
select rtCodeValeur, rtCodeFival, Max(rtDate) from rtRefTitres
where rtCodeFival != '99999'
group by rtCodeValeur, rtCodeFival
- Update the original table by using these 2 views as conditions.

No comments:
Post a Comment