你这个要用到 SQL SERVER 的作业计划,可以定时执行SQL
删除原有的记录
delete a from Daily a inner join dbo.GetChildNode(@DeptId) b on a.DeptId=b.Did where Date between @SDate and @EDate --and (DeptId in (select Did from GetChildNode(@DeptId)) or DeptId is null)
delete a from Daily a where Date between @SDate and @EDate and DeptId is null