title: A SQL Query to select a string between two known strings
body: <p>I need a SQL query to get the value between two known strings (the returned value should start and end with these two strings).</p>
  
  <p>An example.</p>
  
  <p>"All I knew was that the dog had been very bad and required harsh punishment immediately regardless of what anyone else thought."</p>
  
  <p>In this case the known strings are "the dog" and "immediately". So my query should return "the dog had been very bad and required harsh punishment immediately"</p>
  
  <p>I've come up with this so far but to no avail:</p>
  
  <pre><code>SELECT SUBSTRING(@Text, CHARINDEX('the dog', @Text), CHARINDEX('immediately', @Text))
  </code></pre>
  
  <p>@Text being the variable containing the main string.</p>
  
  <p>Can someone please help me with where I'm going wrong?</p>