title: SQL Server : how to remove consecutive duplicate words in a string
body: <p>Currently I have a dynamic query, generated in the stored procedure, that has a bug. Somehow there is a consecutive duplicate 'AND' generated in it.</p>
  
  <p>Wondering if there is a way to delete the CONSECUTIVE DUPLICATE 'AND' from the dynamic query string.</p>
  
  <p>For eg:</p>
  
  <pre><code>var str = 'Select * from employee A where A.age &gt; 30 AND AND A.role = ''developer'''
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>The replace as suggested below doesnt work
  Please see the below query:</p>
  
  <pre><code> DECLARE 
        @str NVARCHAR(MAX)
  
  
  
        SET @str  = 'fasdf asdfasf asfasdfasafsdf AND       AND     asdfasdfasd AND dfasdfa'
  
  
    SET @str = REPLACE(@str, 'AND AND', 'AND')
  
    PRINT @str
  </code></pre>
  
  <p>Thanks!</p>