CTEに含まれるデータを使用してテーブルを更新しようとしています。残念ながら、構文エラーが発生しましたが、その理由はよくわかりません。現在のコードは次のとおりです。
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
私が受け取っている構文エラーは次のとおりです。
メッセージ102、レベル15、状態1、行21「lp」の近くの構文が正しくありません。
私がここで試みようとしていることを行う方法はありますか?私は主題をグーグルで調べてみましたが、行き止まりになりました-アドバイスをいただければ幸いです!