本文介绍了超出最大存储过程嵌套级别(限制32)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用sp和cursor删除多个重复项,但是它会抛出错误
我尝试过:
I try to delete multiple duplicates using sp and cursor, but it throw error
What I have tried:
creat proc uspfixdup
(
@paramID int
)
as
declare @id int
declare _cursor CURSOR LOCAL FAST_FORWARD FOR
select id
from departments dp
where dp.roleid=1
group by id
having count(*)>1
order by id desc
open _cursor
fetch next FROM _cursor INTO @id
while @@FETCH_STATUS = 0
BEGIN
print @id
exec uspfixdup @paramID = @id
fetch next FROM _cursor INTO @id
END
close _cursor
DEALLOCATE _cursor
DECLARE @deptID1 int
DECLARE @deptID2 int
SELECT @deptID1 = deptID
FROM departments
WHERE ID = @paramID
AND RoleID = 1
SELECT deptID2 = deptID
FROM departments
WHERE ID = @paramID
AND RoleID = 1
AND deptID <> @deptID1
IF @deptid1 >1 AND @deptID2>1
BEGIN
IF @depti1 < @deptID2
DELETE FROM departments WHERE deptID = @detID1
ELSE
DELETE FROM departments WHERE deptID = @deptID2
END
ELSE
PRINT 'no duplicate '
GO
推荐答案
这篇关于超出最大存储过程嵌套级别(限制32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!