title: Query in SQL Server 2012 - get a substring
body: <p>In our tool, we use an expression <code>[&amp;SEARCHFIELDS]</code> which converts the UI search criteria into respective SQL Server equivalent code.</p>
  
  <p>In my case it is converted in to the following:</p>
  
  <pre><code>( (CONVERT(DateTime, CONVERT(Varchar(16), ORD.DATBEGIN, 126) + ':00.000' , 126) BETWEEN (CONVERT(DateTime, CONVERT(Varchar(16), Convert(datetime,'2016-07-01 00:00:00',21), 126) + ':00.000' , 126)) AND ( CONVERT(DateTime, CONVERT(Varchar(16), Convert(datetime,'2016-07-13 23:59:59',21), 126) + ':00.000' , 126)))  AND  (ORD.SYSOBJALG = ( 5000088)) )
  </code></pre>
  
  <p>I want to get <code>5000088</code> substring from the above long string, I tried using <code>SELECT RIGHT('Above expression',11)</code> but it is throwing errors as there are multiple single quotes within the above long expression.</p>
  
  <p>Can someone help me?</p>