title: SQL IF ELSE for Inner join with linked dependency
body: <p>I am trying to join data based on two selection criteria with an if else case.
  I have a table with exchange rates (dbo.DATA_EXCHANGE_RATE), one with years (dbo.DATA_EXCHANGE_RATE.YEAR_OBJ_REF) and one with currencies (dbo.DATA_EXCHANGE_RATE.CURRECY_OBJ_REF). If the currency is Euro I want to select my exchange rate only based on currency otherwise based on year and currency. What I have is </p>
  
  <pre><code>select dbo.DATA_EXCHANGE_RATE.EXCHANGE_RATE_CAPTION
  from dbo.DATA_EXCHANGE_RATE
  inner join dbo.measures
  on(CASE WHEN dbo.measures.CURRECY_OBJ_REF =
           (select DATA_ID from dbo.DATA_CURRENCY where CURRENCY_CAPTION = 'T-EUR')
     THEN
        dbo.DATA_EXCHANGE_RATE.CURRECY_OBJ_REF = dbo.measures.CURRECY_OBJ_REF
     ELSE
        dbo.DATA_EXCHANGE_RATE.YEAR_OBJ_REF = dbo.measures.YEAR_OBJ_REF
        and dbo.DATA_EXCHANGE_RATE.CURRECY_OBJ_REF = dbo.measures.CURRECY_OBJ_REF
     END)
  </code></pre>
  
  <p>but this throws an error:</p>
  
  <pre><code>  Failed!
  Incorrect syntax near '='
  </code></pre>