让CTE像:
WITH atree as(SELECT [sort],[object_id],[object_type],[parent_id],[allowed],1 [lvl]
FROM @tbl
WHERE [object_id] in (select object_id from @tbl where allowed = 1)
UNION ALL
SELECT tb.sort , tb.[object_id],tb.[object_type],tb.[parent_id],tb.[allowed], [lvl] + 1 [lvl]
FROM @tbl tb
INNER JOIN atree at ON at.[parent_serno] = tb.[object_serno])
现在想要更新表,如:
UPDATE @tbl
SET allowed = 1 where sort in (select distinct sort from atree)
但更新时出错。如何为CTE编写正确的更新?