title: Struggling with IF statement SQL Beginner
body: <pre><code>UPDATE dbo.Contact
  SET emailMessenger = '63' WHERE personID = @personID
  WHILE (SELECT Email FROM Contact WHERE personID = @personID) != @email
  BEGIN
      IF (SELECT Email FROM Contact WHERE personID = @personID) IS NULL
          UPDATE Contact SET Email = @personID WHERE personID = @personID
      ELSE IF (SELECT Email FROM Contact WHERE personID = @personID) IS NOT NULL
          UPDATE Contact SET SecondaryEmail = email WHERE personID = @personID
          UPDATE Contact SET email = @email WHERE personID = @personID
  END
  </code></pre>
  
  <p>What i'm trying to do is add an employees work email to primaryemail. But if they already have a personal email, then I want to first move that to the secondaryemail. But only for the specified employee hence the PersonID.</p>
  
  <p>I've looked at a lot of different examples using CASE and IF-THEN. I think i'm adding too much to the statement. I really thought this Stackoverflow <a href="https://stackoverflow.com/questions/27716671/updating-multiple-columns-using-case-statement-in-sql-server">queston</a> would help. I know its going to be the syntax or how it's structured.</p>