title: Insert and update in single stored procedure not working
body: <p>When a user updates his profile picture, I want to insert it into a table and update just two columns in another table. It works fine for just one entry and stopped updating 2nd table.. don't know what is the error</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[UploadProfilePic]
       (@UserName Nvarchar(50),
        @ImageName Nvarchar(max),
        @OrgImageName Nvarchar(max),
        @CommentImage Nvarchar(max))
  AS 
  BEGIN
      IF NOT EXISTS (SELECT Username FROM ProfilePic WHERE UserName = @UserName)
      Begin
            insert into ProfilePic ([UserName], [ImageName], [OrgImageName], [IsActive], [CommentImage])
            values(@UserName, @ImageName, @OrgImageName, 'Y', @CommentImage)
  
            Update UserProfile 
            set ProfileImg = @ImageName,
                PostImage = @CommentImage
            where UserName = @UserName
      END
      ELSE
      BEGIN
         UPDATE ProfilePic 
         SET IsActive = 'N' 
         WHERE UserName = @UserName
  
         INSERT INTO ProfilePic ([UserName], [ImageName], [OrgImageName], [IsActive],[CommentImage])
         VALUES(@UserName, @ImageName, @OrgImageName, 'Y', @CommentImage)
     END
  END
  </code></pre>