title: How to use tSQL to match and remove everything after a string?
body: <p>How can I use tSQL to find a string, and if it exists, return everything before that string?</p>
  
  <p>i.e. in the example below, in an ETL process, how would we take the column from source, identify the string ?uniquecode= and therefore remove that, and everything else after it, in the SELECT statement for the sink column?</p>
  
  <p><a href="https://i.stack.imgur.com/7bCZA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7bCZA.jpg" alt="Source Column to Sink Column, removing identified match and beyond"></a></p>
  
  <p>How can I best modify this tSQL statement below to return the values in SinkPageURL column above?</p>
  
  <pre><code>SELECT SourcePageURL FROM ExampleTable
  </code></pre>
  
  <p>I have attempted a Fiddle here - <a href="http://sqlfiddle.com/#!18/3b60a/4" rel="nofollow noreferrer">http://sqlfiddle.com/#!18/3b60a/4</a> using the below statement.  It is disregarding the values where '?uniquecode=' does not exist though, and also leaves the '?' symbol.  Need this to work with MS SQL Server '17.</p>
  
  <p>Somewhat close, but no cigar.  Help appreciated!</p>
  
  <pre><code>SELECT LEFT(SourcePageURL, CHARINDEX('?uniquecode=', SourcePageURL)) FROM sql_test
  </code></pre>