Jason writes "----------Background of problem I inherited a database for tracking equipment request and processing.The stored procedure would need to scan the table and change any priority of the same value or higher by adding a one to them. In this way, any priority values of 2 would be changed to a 3 if we are adding a priority 2 value. for a specific Service.The Maintable is called : er2001maintable er2001maintable.EILer2001maintable.Priorityer2001maintable.RequestID --() primary Keyer2001maintable.EquipNomenclature....... more data fields...Table where Requesting Service info : eilvieweilview.EIL --() primary keyeilview.ReqServiceeilview.Expr1How to increment priority in a cursor for all request for specific requesting service?(i.e ReqService='DIRECTOR' EIL=00D ReqService='DIRECTOR' EIL=010 ReqService='DIRECTOR' EIL=012 ) Only ONE #1 priority is allowed per Service No matter how many different EIL's a Service has.---------------------------------------What I have so far using a cursor. It updates the priority + 1 for ALL SERVICES. I need to limit the update to a specific Service. (i.e. if ReqService = 'Director' update All A.Priority WHERE B.ReqService = 'Director')------------- code with cursor ---------------------------CREATE Procedure Crsr1_update ASDECLARE @priority int, @Service nvarchar(50),@ReqSERVICE nvarchar(50)DECLARE Crsr1 CURSOR FORSELECT A.priority,B.ReqServiceFROM er2001maintable A,eilview BWHERE A.priority > 2 AND A.EIL = B.EILFOR UPDATE OF A.PriorityOPEN Crsr1 -- OPEN ABOVE SELECTION FOR UPDATEFetch NEXT FROM Crsr1 -- 1st FETCH INTO @PRIORITYINTO @priority, @ServiceWHILE @@FETCH_STATUS = 0 --AND @Service = A Specific SERVICE --WHILE FETCH statement was successful.BEGIN -- BEGIN WHILE PRINT @Service -- display @Service value FETCH NEXT FROM Crsr1 -- move to next record INTO @priority,@Service UPDATE er2001maintable -- UPDATE TABLE SET priority = priority + 1 -- increment priority + 1 WHERE current of Crsr1 -- ***ON CURRENT VALUE!** PRINT @priority -- display @priority valueEND -- END WHILECLOSE Crsr1 -- Close Cursor Crsr1DEALLOCATE Crsr1 -- Deallocate cursor Crsr1
Thanks in Advance for any thoughts on how to fix my code or rewrite needed. platforms used:SQL 2000 Server 2000 SP2ACCESS 2000 Data Access Pages ( on Intranet)// Jason"