title: Using parameters of Stored Procedure with Join's "ON" area
body: <p>I have parameters like these</p>
  
  <pre><code>declare @Phl1_descr varchar(50)
  SET @Phl1_descr = 'Greece'
  
  declare @Phl2_descr varchar(50)
  SET @Phl2_descr = 'Coffee &amp; Beverages'
  </code></pre>
  
  <p>I want to join two tables with the above parameters <strong>(if they are not null)</strong>, so I tried to do something like below in the "<code>ON</code>" keyword of my <code>JOIN</code></p>
  
  <pre><code>ON 
        (CASE WHEN LEN(@Phl1_descr) &gt; 0 THEN A.Phl1_descr ELSE B.Phl1_descr END) = B.Phl1_descr AND
        (CASE WHEN LEN(@Phl2_descr) &gt; 0 THEN A.Phl2_descr ELSE B.Phl2_descr END) = B.Phl2_descr
  </code></pre>
  
  <p>However if I send one of the parameters like as <code>''</code>, it doesn't work. Any simpler idea?</p>