title: More efficient double coalesce join alternative
body: <p>I have a procedure with a (slightly more complex) version of the below:</p>
  
  <pre><code>CREATE PROC sp_Find_ID (
      @Match1 varchar(10),
      @Match2 varchar(10)
  ) AS
  
  DECLARE @ID int
  
  SELECT @ID = ID
  FROM Table1
  WHERE Match1 = @Match1
      AND Coalesce(Match2,@Match2,'') = Coalesce(@Match2,Match2,'')
  
  SELECT @ID ID
  </code></pre>
  
  <p>Essentially Match1 is a mandatory match, but Match2 is both optional on the input to the procedure, and on the table being searched. The 2nd match succeeds where the input and/or the table Match2 values are null, or where they're both the same (not null) value.</p>
  
  <p>My question is: Is there a more efficient (or even more readable) way of doing this?</p>
  
  <p>I've used this method a few times, and I feel slightly sullied each time (subjective dirtiness admittedly).</p>