Domanda

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.

I found that running IsNull on its own worked fine on 15.7:

select IsNull((SELECT 9 WHERE 5 != 5),-1) -- returns -1

However, trying to assign the return value to a variable did not work:

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

Adding a 'from table' clause makes it work:

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'

But removing the 'from table' clause breaks it:

declare @eff_d datetime
select @eff_d = IsNull((select '09/09/1990' WHERE 5!=5),'01/01/1800')
select @eff_d -- returns blank

Finally, turning on COMPATIBLITY_MODE before executing also fixes it:

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'

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?

Are there other ways to ensure the variable will get set?

È stato utile?

Soluzione

Our DBAs worked with Sybase and this issue has been logged as a bug by Sybase: CR 742233, “Queries performing isnull() on a variable assignment may return null when ‘streamlined dynamic SQL’ is enabled.”

The workaround is to disable “streamlined dynamic SQL”.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top