I'm trying to update a table using data contained in a CTE. Unfortunately I'm receiving a syntax error and I'm not quite sure why. The code currently is:
declare @period_id integer =
(
select period_id
from property.period
where getdate() between period_start and period_end
)
;with cte_reclassified as
(
select building_id ,
lease_id ,
scca_broad_category_code ,
scca_fine_categories_code ,
scca_notes_code ,
scca_sales_group_code ,
scca_uplift
from property.lease_period
where period_id = @period_id
)
update property.lease_period lp
from cte_reclassified r
set lp.scca_broad_category_code = r.scca_broad_category_code
where lp.lease_id = r.lease_id
and lp.building_id = r.building_id
The syntax error I'm receiving is:
Msg 102, Level 15, State 1, Line 21 Incorrect syntax near 'lp'.
Is there a way to do what i'm trying to attempt here? I've tried googling the subject but hit dead ends - any advice would be appreciated!