I am getting an error that states #Plans is ambiguous. This happens when I am joining a table to itself on a self join and am not sure why. Here is the code that leads to the error:
Alter Table #Plans
Add SecondPlanDate date
Update #Plans
Set
SecondPlanDate = Min (P2.PlanPurchaseDate) Over (Partition By P1.PatientID, P1.PlanPurchaseDate)
From
#Plans as P1
Inner Join
#Plans as P2
on
P1.PatientID = P2.PatientID
Where
P2.PlanPurchaseDate > P1.PlanPurchaseDate
;
Select
*
From
#Plans
Any suggestions would be greatly appreciated.
Thanks,
I think you need to use the table alias:
UPDATE P1
SET P1.SecondPlanDate ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With