title: SQL Server: ISNULL on uniqueidentifier
body: <p>I am trying to compare a column <code>col1</code> and a variable <code>@myvar</code> in a <code>WHERE</code> clause. Both usually contain GUIDs, but may also have NULL values. 
  I thought I could get around the fact that <code>NULL=NULL</code> evaluates to FALSE by using <code>WHERE ISNULL(col1, '')=ISNULL(@myvar, '')</code>. That would compare two empty strings instead, and evaluate to TRUE.</p>
  
  <p>This will, however, produce the following error message:</p>
  
  <blockquote>
    <p>Msg 8169, Level 16, State 2, Line 3 Conversion failed when converting
    from a character string to uniqueidentifier.</p>
  </blockquote>
  
  <p>I tried</p>
  
  <pre><code>DECLARE @myvar uniqueidentifier = NULL
  SELECT ISNULL(@myvar,'') as col1
  </code></pre>
  
  <p>Same error message.</p>
  
  <p>Two questions:
  First, I am trying to convert a uniqueidentifier variable - even though it has a NULL value - to an (empty!) string, not the other way around, as the error message suggests. What gives? </p>
  
  <p>Second, is there a better way to word that WHERE clause I need, to allow for comparing uniqueidentifiers that might be NULL?</p>