I understand that this
IF EXISTS(SELECT NULL) PRINT 'TRUE';
would always print TRUE because after all NULL is a value in SQL Server but why would this
IF EXISTS(SELECT NULL) PRINT 'TRUE'
print TRUE as the sub query would cause an error and EXISTS always checks for existence so how come this is possible.
Guessing because there is a copy/paste error in your question
EXISTS doesn’t check for values. It checks for rows.
So these are valid because the SELECT gives one row
To explain, we’ll look at ANSI-92 SQL, search for “
Query expressions 191“.This is case 3a (my bold):
So, this says you can have any old rubbish in the EXISTS bit: it should be ignored