title: OPENJSON - modify statement to ignore first part of the string
body: <p>We receive auto-generated emails from an application, and we export those to our database as they arrive at the Inbox.  The table is called <code>dbo.MailArchive</code>.</p>
  
  <p>Up until recently, the body of the email has always looked like this...</p>
  
  <pre class="lang-none prettyprint-override"><code>Status: Completed
  Successful actions count: 250
  Page load count: 250
  
  </code></pre>
  
  <p>...except with different numbers and statuses. <strong>Note that there is a carriage return on the blank line after Page load count.</strong></p>
  
  <p>The entirety of this data gets written to a field called <code>Mail_Body</code> - then we run the following statement using <code>OPENJSON</code> to parse those lines into their own columns in the record:</p>
  
  <pre class="lang-sql prettyprint-override"><code>DECLARE @PI varchar(7) = '%[^' + CHAR(13) + CHAR(10) + ']%';
  
  SELECT j.Status,
         j.Successful_Actions_Count,
         j.Page_Load_Count
  FROM dbo.MailArchive m
       CROSS APPLY(VALUES(REVERSE(m.Mail_Body),PATINDEX(@PI,REVERSE(m.Mail_Body)))) PI(SY,I)
       CROSS APPLY(VALUES(REVERSE(STUFF(PI.SY,1,PI.I,''))))S(FixedString)
       CROSS APPLY OPENJSON (CONCAT('{"', REPLACE(REPLACE(S.FixedString, ': ', '":"'), CHAR(13) + CHAR(10), '","'), '"}')) 
                   WITH (Status varchar(100) '$.Status',
                         Successful_Actions_Count int '$."Successful actions count"',
                         Page_Load_Count int '$."Page load count"') j;
  </code></pre>
  
  <p>Beginning today, there are certain emails where the body of the email looks like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>Agent did not meet defined success criteria on this run.
  
  Status: Completed
  Successful actions count: 250
  Page load count: 250
  </code></pre>
  
  <p>To clarify, that's one new line at the top, a carriage return at the end of that line, and a carriage return on the blank line between the new line and the <code>Status</code> line. At this time, there is no consistent way to predict which emails will come in with this new line, and which ones won't.</p>
  
  <p>How can I modify our <code>OPENJSON</code> statement to say, If this first line exists in the body, skip/ignore it and parse lines 3 through 5, else just do exactly what I have above?  Or perhaps even better to future-proof it, always ignore everything before the word <code>Status</code>?</p>