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