DECLARE MyCursor CURSOR
FOR select id,code from INM_MaterialExtend order by Code,Sys4Version
--打开一个游标
OPEN MyCursor
--循环一个游标
DECLARE @TempId uniqueidentifier ,@TempCode nvarchar(50) ,@OldCode nvarchar(50)
FETCH NEXT FROM MyCursor INTO @TempId, @TempCode
WHILE @@FETCH_STATUS =0
BEGIN
if(@OldCode=@TempCode)
begin
--delete INM_MaterialExtend where id=@TempId
print @TempId
end
set @OldCode=@TempCode
FETCH NEXT FROM MyCursor INTO @TempId, @TempCode
END
--关闭游标
CLOSE MyCursor
--释放资源
DEALLOCATE MyCursor