Hi all
I have a partitioned table in SQL2005 database based on the year
Years prior to 2007 are read only
When I execute the following statement I get the error
Msg 652, Level 16, State 1, Line 1
The index "pkSettleCase2" for table "dbo.tbSettle_Case" (RowsetId 72057594130661376) resides on a read-only filegroup, which cannot be modified.
UPDATE SC
SET ReadyToCalc = SCDA.ReadyToCalc
FROM tbSettle_Case AS SC
JOIN tbSettle_Case_Data_Availability AS SCDA ON SC.SettleKey = SCDA.SettleKey
WHERE ISNULL(SC.ReadyToCalc, 0)= 0
and ISNULL(SCDA.ReadyToCalc, 0)= 1
and sc.BillYearWeek >= (year(getdate())-1 )* 100 -- only update this and previous year ( billyearweek has format YYYYww )
Now if this query returns NO rows to update – I still get the error
If I change the query to use a cursor such as
Declare @Settlekey int
Declare cUpdate cursorlocalstaticfor
Select SC.Settlekey
FROM tbSettle_Case AS SC
JOIN tbSettle_Case_Data_Availability AS SCDA
ON SC.SettleKey = SCDA.SettleKey
WHERE ISNULL(SC.ReadyToCalc, 0)= 0
ANDISNULL(SCDA.ReadyToCalc, 0)= 1
and sc.BillYearWeek >= (year(getdate())-1 )* 100 -- only update this and previous year
open Cupdate
Fetchnextfrom Cupdate into @Settlekey
while@@fetch_status= 0 begin
Update tbSettle_Case set ReadyToCalc=1 where settlekey = @Settlekey
Fetchnextfrom Cupdate into @Settlekey
end
close cUpdate
Deallocate cUpdate
It all works FINE – even with updates
SO how does SQL determine what is a ‘safe update’ with a partitioned table that resides on some read-only only file groups ???
thx Ewen