title: IsNull behaves differently between Sybase 12.5 and 15.7
body: <p>I am upgrading an application to connect to Sybase ASE 15.7 database servers instead of 12.5. When I switched it over, a stored procedure's behavior changed which caused problems with the application. I narrowed the cause down to the IsNull function being called inside the procedure.</p>
  
  <p>I found that running IsNull on its own worked fine on 15.7:</p>
  
  <pre><code>select IsNull((SELECT 9 WHERE 5 != 5),-1) -- returns -1
  </code></pre>
  
  <p>However, trying to assign the return value to a variable did not work:</p>
  
  <pre><code>DECLARE @key_clnt_id_n int
  SELECT  @key_clnt_id_n = IsNull((SELECT 9 WHERE 5 != 5),-1)
  select @key_clnt_id_n -- returns blank
  </code></pre>
  
  <p>Adding a 'from table' clause makes it work: </p>
  
  <pre><code>declare @eff_d datetime
  select @eff_d = IsNull((select '09/09/1990' from db_table db WHERE 5!=5),'01/01/1800')
  select @eff_d -- returns '01/01/1800'
  </code></pre>
  
  <p>But removing the 'from table' clause breaks it:</p>
  
  <pre><code>declare @eff_d datetime
  select @eff_d = IsNull((select '09/09/1990' WHERE 5!=5),'01/01/1800')
  select @eff_d -- returns blank
  </code></pre>
  
  <p>Finally, turning on COMPATIBLITY_MODE before executing also fixes it:</p>
  
  <pre><code>declare @eff_d datetime
  SET COMPATIBILITY_MODE ON
  select @eff_d = IsNull((select '09/09/1990' WHERE 5!=5),'01/01/1800')
  SET COMPATIBILITY_MODE OFF
  select @eff_d -- returns '01/01/1800'
  </code></pre>
  
  <p>What is going on in the 15.7 databases that causes this? Is the query in the IsNull causing the whole statement to short-circut and not assign a value to the variable?</p>
  
  <p>Are there other ways to ensure the variable will get set?</p>