传入xml,在树表中递归,再归组加入其他表

前端之家收集整理的这篇文章主要介绍了传入xml,在树表中递归,再归组加入其他表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
declare @uid int
set @uid=1

declare @doc xml
set @doc=N'
<ids>
<sid id="001001" />
<sid id="001001009" />
</ids>'

--找出指定类的所以子类,加入表中
declare @p int
exec sp_xml_preparedocument @p OUTPUT,@doc  
 
delete from t_dor_operatorStruct where uid=@uid
;with tmp (unitId)
as
(
	select unitId from t_scs_schoolStructure 
	where fartherId in(SELECT id FROM OPENXML (@p,'/ids/sid',1) WITH (id varchar(50)))
	union all
	select t_scs_schoolStructure.unitId from t_scs_schoolStructure 
	inner join tmp on tmp.unitId=t_scs_schoolStructure.fartherId
)

insert into t_dor_operatorStruct(uid,sid) select @uid,unitId from tmp group by unitid

exec sp_xml_removedocument @p

猜你在找的XML相关文章