Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

NULL and empty string question...

$
0
0
I have always (or at least intended to) treat NULL and empty strings separately in my SQL querying history. Now I have run across something that mystifies me (but probably shouldn't) that I would like an explanation for. Consider this bit o' code:[code="other"]DECLARE @ORDER CHAR(10)SET @ORDER= ( SELECT NULL)IF @ORDER <> '' PRINT 'Not an empty string'IF @ORDER IS NULL PRINT 'It is NULL'[/code]Run this and you will get:[i]It is NULL[/i]I was expecting: [i]Not an empty stringIt is NULL[/i]Why is NULL not passing the 'not an empty string' test? In other words, how does NULL = '' ? Is NULL cast to an empty string for this comparison?Hopefully my feeling mystified is just from not enough caffeine yet.

Viewing all articles
Browse latest Browse all 3145

Latest Images

Trending Articles



Latest Images