呼唤远方
--声明变量Declare @ID Int, @PosNo IntDeclare @Table Table(ID Int,PosNo int)Declare cur Cursor Static READ_ONLY ForSelect ID, PosNoFrom 表Order By EmpID, IDOpen curFetch From cur Into @ID, @PosNoWhile @@FETCH_STATUS = 0BeginIf Exists(Select * From @Table Where PosNo = @PosNo)BeginDelete 表 Where ID = @IDEndElseBeginInsert Into @Table (ID, PosNo)Values (@ID, @PosNo)EndFetch Next From cur Into @ID, @PosNoEndClose curDeAllocate cur