title: How can I use LTRIM/RTRIM to search and replace leading/trailing spaces?
body: <p>I'm in the process of trying to clear out leading and trailing spaces from an NVARCHAR(MAX) column that is filled with prices (using NVARCHAR due to data importing from multiple operating systems with odd characters).  </p>
  
  <p>At this point I have a t-sql command that can remove the leading/trailing spaces from static prices.  However, when it comes to leveraging this same command to remove all prices, I'm stumped.</p>
  
  <p>Here's the static script I used to remove a specific price:</p>
  
  <pre><code>UPDATE *tablename* set *columnname* = LTRIM(RTRIM(2.50)) WHERE cost = '2.50 ';
  </code></pre>
  
  <p>Here's what I've tried to remove all the trailing spaces:</p>
  
  <pre><code>UPDATE *tablename* set *columnname* LIKE LTRIM(RTRIM('[.]')) WHERE cost LIKE '[.] ';
  </code></pre>
  
  <p>I've also tried different varations of the % for random characters but at this point I'm spinning my wheels.</p>
  
  <p>What I'm hoping to achieve is to run one simple command that takes off all the leading and trailing spaces in each cell of this column without modifying any of the actual column data.</p>