title: MS SQL Server: cast double to string and compare text
body: <p>In MS SQL Server I have a filed of type double that is called <code>ID</code>, and that stores ID numbers, surprisingly enough.
  Anyway, I want to be able to search ID numberss like text - say I want all ID's that starts with 021 or that ends with 04 - to do so I need to convert the double the string.</p>
  
  <p>My problem is that ID numbers here are 9 digits, so when I try <code>SELECT str([id])</code> I get something like <code>02123+e23</code>, which is not good for my purpose.</p>
  
  <p>How do I go about converting it to a string that looks exactly the same, and can be compared against other strings?</p>
  
  <p>EDIT: I tried <code>SELECT str([id],9,0)</code> and I got the right string, or at least what looked right to me, but when comparing against equal strings the comparison failed. Any ideas why?</p>
  
  <p>Thanks!</p>