Dear fellow SQL Server programmers,
I would like to have ANSI_WARNINGS set to ON. I know that this causes statements like the example below to give a warning. This seems to have an unfortunate side effect, however. If you run a stored proc that issues large numbers of ANSI warnings, the SQL Server Native Client DLL seems to store the warnings in memory on the client. Large amounts of memory are grabbed from the heap by this DLL. In some cases, the proces event stops with an 'out of memory' error. If I run the statement from management studio, these problems do not occur. By the way, we use SQL Server 2008 R2 and SQL Server 2012. Both show the same behaviour. I need your advice on how to solve this problem.
Let me show you the test code first.
USE tempdb; GO SET NOCOUNT ON; SET ANSI_WARNINGS ON; GO CREATE TABLE #NULL_Warning (i int null); INSERT INTO #NULL_Warning VALUES (1), (NULL); GO SELECT SUM(i) FROM #NULL_Warning; -- Warning: Null value is eliminated by an aggregate or other SET operation. GO DROP TABLE #NULL_Warning; GO
How should I progress?
- Turn ANSI_WARNINGS off?
- Change the statement to 'SELECT SUM(i) FROM #NULL_Warning WHERE i IS NOT NULL''?
- Change the statement to 'SELECT SUM(ISNULL(i,0)) FROM #NULL_Warning'?
- Some other way?