title: Convert varchar to uniqueidentifier in SQL Server
body: <p>A table I have no control of the schema for, contains a column defined as varchar(50) which stores uniqueidentifiers in the format 'a89b1acd95016ae6b9c8aabb07da2010' (no hyphens)</p>
  
  <p>I want to convert these to uniqueidentifiers in SQL for passing to a .Net Guid. However, the following query lines don't work for me:</p>
  
  <pre><code>select cast('a89b1acd95016ae6b9c8aabb07da2010' as uniqueidentifier)
  select convert(uniqueidentifier, 'a89b1acd95016ae6b9c8aabb07da2010')
  </code></pre>
  
  <p>and result in:</p>
  
  <pre>Msg 8169, Level 16, State 2, Line 1
  Conversion failed when converting from a character string to uniqueidentifier.</pre>
  
  <p>The same queries using a hyphenated uniqueidentifier work fine but the data is not stored in that format.</p>
  
  <p>Is there another (efficient) way to convert these strings to uniqueidentifiers in SQL. -- I don't want to do it in the .Net code.</p>