Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CTE error 4405

Status
Not open for further replies.

mkrausnick

Programmer
Apr 2, 2002
766
0
0
US
I'm getting
Code:
Msg 4405, Level 16, State 1, Line 1
View or function 'overlap' is not updatable because the modification affects multiple base tables.

However, I'm only referencing one table.

The purpose of the CTE is to identify and consolidate overlapping insurance enrollment periods. It is run from a stored procedure stored in a different database. 'ACE' is the code for the insurance program.

Here's the CTE:
Code:
;with overlap as (
select Enrollment_ID as Ace1Enrollment_ID,pid as Ace1Pid,Ins_Eff_Dt as Ace1EffDate,Ins_End_Dt as Ace1EndDate, 
	ace.AceEnrollment_ID, ace.acepid,ace.aceEffDate,ace.aceEndDate,
	case when Ace1.Ins_Eff_Dt < ace.aceEffDate then Ace1.Ins_Eff_Dt else ace.aceEffDate end as MinEffDate,
	case when Ace1.Ins_End_Dt > ace.aceEndDate then Ace1.Ins_End_Dt else ace.aceEndDate end as MaxEndDate
	from [Oneeapp].[dbo].oea_program_enrollment Ace1 
inner join (
	select Enrollment_ID as aceEnrollment_ID,pid as acePid,
			Ins_Eff_Dt as aceEffDate,Ins_End_Dt as aceEndDate , 
			CONVERT(datetime,'') as ModStartDate
		from [Oneeapp].[dbo].oea_program_enrollment	where Prog_Id = 'ACE') ace
	on Ace1.pid = acepid and Ace1.Ins_Eff_Dt between aceEffDate and aceEndDate and Ace1.Ins_End_Dt > aceEndDate
	where  Ace1.Prog_Id = 'ACE' and Ace1.Enrollment_ID <> Ace.aceEnrollment_ID )
update overlap set Ace1EffDate=MinEffDate, Ace1EndDate=MaxEndDate,aceEffDate=MinEffDate,aceEndDate=MaxEndDate

Only one table is referenced, right? Any ideas as to why this doesn't work?

Thanks for your help.

Mike Krausnick
Dublin, California
 
I'm not familiar with the 'overlap' thing, so I could be wrong about this. But I believe that is two tables. One just happens to be a derived table, but it is still a table.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
and you are trying to update a CTE (overlap), and update fields from both the CTE and the underlying table oea_program_enrollment.

It kind of doesn't make sense to me.

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Hmmm. I don't understand. The entire CTE is based on only one table: oea_program_enrollment. It is joined to itself. Does CTE take the two parts of the join to be separate tables even though they are based on the same underlying table? To make things even more confusing, the following CTE, on which the one I posted is based, does not get the error. The purpose of this is similar: to detect and resolve enrollment period conflicts among multiple insurance plans.
Code:
- CMSP period overlaps end of ACE period; set CMSP start date to follow ACE end date
;with overlap as (
select Enrollment_ID as cmspEnrollment_ID,pid as CmspPid
	,Ins_Eff_Dt as CmspEffDate,Ins_End_Dt as CmspEndDate, 
	ace.AceEnrollment_ID, ace.acepid,ace.aceEffDate,ace.aceEndDate
	from [Oneeapp].[dbo].Oea_program_enrollment cmsp 
inner join (
	select Enrollment_ID as aceEnrollment_ID,pid as acePid
			,Ins_Eff_Dt as aceEffDate,Ins_End_Dt as aceEndDate 
			, CONVERT(datetime,'') as ModStartDate
		from [Oneeapp].[dbo].Oea_program_enrollment	where Prog_Id = 'ACE') ace
	on cmsp.pid = acepid 
		and Cmsp.Ins_Eff_Dt between aceEffDate and aceEndDate 
		and Cmsp.Ins_End_Dt > aceEndDate
	where  cmsp.Prog_Id = 'CMSP' )
update overlap set cmspEffDate=dateadd(d,1,aceEndDate)

I note that in first CTE, I'm updating both "halves" of the self-join, whereas in the second CTE I'm updating only one half of the self-join. Could that be the issue?


Mike Krausnick
Dublin, California
 
on this last example you are only updating ONE table, not two as on your original post, so yes I would say that is the issue

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top