do you mean this?SELECT t.priceindex, t.pricedate,t.price,t1.RunAvg * CASE WHEN t.priceindex IN (1,2) THEN 0.6 WHEN t.priceindex IN (3,4,5,6) THEN 0.2 END AS AvgValFROM table tCROSS APPLY (SELECT AVG(price*1.0) AS RunAvg FROM table WHERE priceindex=t.priceindex AND pricedate >= DATEADD(dd,DATEDIFF(dd,0,t.pricedate),-19) AND pricedate < DATEADD(dd,DATEDIFF(dd,0,t.pricedate),1) ORDER BY pricedate DESC)t1
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/