title: Remove unwanted characters from a string with SQL
body: <p>I tried a query to get the below result from a string. But its not showing the accurate result.</p>
  
  <ul>
  <li><p>String: ty-R<br>
  Desired Output: ty</p></li>
  <li><p>String: tuy-R<br>
  Desired Output: tuy</p></li>
  </ul>
  
  <p>I tried using replace function. But I am unable to remove the next hyphen as I have to use the first one. </p>
  
  <pre><code>DECLARE @str NVARCHAR(MAX);
  DECLARE @lpcounter INT;
  
  SET @str = 'ty-R ';
  SET @lpcounter = 0;
  
  WHILE @lpcounter &lt;= 26
  BEGIN
      SET @str = REPLACE(@str, CHAR(65 + @lpcounter), '');
      SET @lpcounter = @lpcounter + 1;
  END;
  
  SELECT @str;
  </code></pre>
  
  <p>Can this be done through a query only?</p>