title: Query to return substring from string in SQL Server
body: <p>I have a user defined function called <code>Sync_CheckData</code> under Scalar-valued functions in Microsoft SQL Server. What it actually does is to check the quantity of issued product and balance quantity are the same. If something is wrong, returns an <code>ErrorStr nvarchar(255)</code>.</p>
  
  <p>Output Example:</p>
  
  <pre><code>Balance Stock Error for Product ID : 4
  </code></pre>
  
  <p>From the above string, I want to get 4 so that later on I can SELECT the rows which is giving errors by using <code>WHERE</code> clause (<code>WHERE Product_ID = 4</code>). </p>
  
  <p>Which SQL function can I use to get the <code>substring</code>?</p>