title: Count the amount of Cases and set Status on CaseStatus table if every counted amount is the statusCode 601 in the Cursor
body: <p>Hello I made a cursor that check every row and check the status of the Caseinventory and then sets the status on the caseStatus. Problem is if I set the last counted row to 601 and it changes the code to 3 (shown in the code) it will not check if the rest is 601 and then just set the status to 3 even though rest is 600 or 599.
  How can I solve this? should I count the amount on the CaseInventory and then check the status on every counted row and then update if the value is 601? and how do you do this? first time using cursor.</p>
  <pre><code>ALTER PROCEDURE [dbo].[SetsStatusOnCaseStatusByCaseInventoryStatus]
      @StatusID INT,
      @ID int,
      @CaseInventoryID int
  AS
  BEGIN
  --find caseID on CaseInventoryID
  declare @CaseID int = (SELECT CaseID from [dbo].[factCaseInventory] where ID=@ID)
  
  --CaseStatus
  declare @CaseIkkeStartet int =1
  declare @CaseIgangStatus int = 2
  declare @CaseDoneStatus int = 3
  
  --CaseInventoryStatus
  DECLARE @NotStarted int = 599
  DECLARE @Nocode int = 600
  declare @YesCode int = 601
  
  --Cursor
  declare CaseInventoryCursor cursor for 
  Select ID, StatusID, CaseID from [dbo].[factCaseInventory] 
  
  open CaseInventoryCursor
  
  fetch next from CaseInventoryCursor into @ID, @StatusID, @CaseID
  
  while(@@FETCH_STATUS = 0)
  begin 
  
  SELECT @StatusID =StatusID from [dbo].[factCaseInventory] where CaseID=@CaseID
  
  if(@StatusID = @Nocode)
  begin 
  update [dbo].[factCase] set CaseStatusID=@CaseDoneStatus where CaseId=@CaseID
  end
  
  else if (@StatusID =@YesCode)
  begin
  update [dbo].[factCase] set CaseStatusID=@CaseIgangStatus where CaseId=@CaseID
  end
  
  else if (@StatusID =@NotStarted)
  begin
  update [dbo].[factCase] set CaseStatusID=@CaseIkkeStartet where CaseId=@CaseID
  end
  
  fetch next from CaseInventoryCursor into @ID, @StatusID, @CaseID
  
  end
  close CaseInventoryCursor
  deallocate CaseInventoryCursor
  
  END
  
  
  </code></pre>