If the XML data type exist() function returns NULL and is used in comparison with 0, the comparison returns NULL in SQL 2012. Such comparison returned TRUE in previous versions. Consider the following code:DECLARE @test AS XML;

SET @test = NULL;

— Returns 0 in SQL 2012, and 1 in earlier editions

SELECT COUNT(1) WHERE @test.exist(‘/whatever’) = 0;

— Returns 1 in all editions

SELECT COUNT(1) WHERE @test.exist(‘/whatever’) IS NULL;

The first query returns 1 in previous editions, while according to other NULL comparisons in SQL Server 0 is expected. This behavior is more consistent than in previous versions.

Dejan Sarka