title: SQL Server - update multiple records using a stored procedure
body: <p>Being a super novice at this, I would like some guidance on this, please. </p>
  
  <p>I need to compare two sets of data and update one set with a value. This is what I have so far.</p>
  
  <pre><code>PROCEDURE [dbo].[update_personnel_rank]
  AS
      DECLARE @frsid VARCHAR
      DECLARE @officerid VARCHAR
      DECLARE @hrrank VARCHAR
      DECLARE @personnelrank VARCHAR
      DECLARE @farank VARCHAR
  
      DECLARE @rank VARCHAR(150)
  
      SET @rank = 'Admin Spec II'
  BEGIN
      SET NOCOUNT ON;
  
      SELECT
          @frsid = hr.FRSID, 
          @officerid =  p.OfficerID,
          @hrrank =  hr.Rank,
          @personnelrank = p.Rank, 
          @farank =  r.FA_Rank
      FROM 
          [FireApp_REPL_DW_Data].[dbo].[MCFRSCombinedPersonnelandPimsStaff] hr 
      INNER JOIN
          [fh_reports].[dbo].[personnel_bk] p ON p.OfficerID = hr.FRSID
      INNER JOIN
          [fh_reports].[dbo].[Rank_Lookup_tbl] r ON r.FA_Rank = hr.Rank
      WHERE
          (p.rank &lt;&gt; hr.Rank OR p.rank = '')
          AND p.Rank = @rank
  
      UPDATE [fh_reports].[dbo].[personnel_bk]
      SET Rank = @farank
      WHERE OfficerID =  @officerid
  END
  GO
  </code></pre>
  
  <p>The select query returns 3 records and this stored procedure runs without any error, but it does not update the records. Since the select query returns 3 records, I think I need to change the parameter setting accordingly, but not sure how... </p>