title: Nested If Statement with Insert Statements in SQL
body: <p>So I am writing a stored procedure for a webpage that will pull 3 parameters from the webpage and then store one based on the values of the other 2.</p>
  
  <pre><code>ALTER  PROCEDURE [dbo].[PMRAssignDate]
  
                  @PMRID int,
                  @Department varchar(255),
                  @AssignDate date
  AS
  BEGIN
      IF EXISTS(SELECT * FROM [ProductInformation].[dbo].[PMRInformation] WHERE PMRID = @PMRID)
  
          Begin
          IF @Department='Engineering'
              Begin
              Insert INTO
                      [dbo].[PMRInformation]
                      (EngineeringApprovalDate)
              Values
                      (@AssignDate)
              End
  
          Else IF (@Department='Operations')
              Begin
              Insert INTO
                      [dbo].[PMRInformation]
                      (OperationsApprovalDate)
              Values
                      (@AssignDate)
                  End
          Else IF (@Department='AME')
              Begin
              Insert INTO
                      [dbo].[PMRInformation]
                      (AMEApprovalDate)
              Values
                      (@AssignDate)
              End
          Else IF @Department='Finance'
              Begin
              Insert INTO
                      [dbo].[PMRInformation]
                      (FinanceApprovalDate)
              Values
                      (@AssignDate)
                      End
          Else IF @Department='Marketing'
          Begin
              Insert INTO
                      [dbo].[PMRInformation]
                      (MarketingApprovalDate)
              Values
                      (@AssignDate)
          End
          Else IF @Department='Tester'
              Begin
              Insert INTO 
                      [dbo].[PMRInformation]
                      (EngineeringApprovalDate, MarketingApprovalDate, AMEApprovalDate, FinanceApprovalDate, OperationsApprovalDate)
              Values
                      (@AssignDate,@AssignDate,@AssignDate,@AssignDate,@AssignDate)
      End     
  
      End End
  </code></pre>
  
  <p>So this stored procedure must find the row where the PMRID equals the sent @PMRID from the webpage. Then it must use the @Department variable to determine which department to store the approval date @AssignDate into. So far the procedure runs but it is not storing the date in the correct row. It will create a new row and insert the approval date into that new row. Could you please help. Thanks!</p>