The correct answer is: A is '' (empty string), B is 'Chris'.
Try this code:
declare @name varchar(12)
select @name = 'Christopher'
select case when substring(@name,15,12) is null then 'NULL' else 'NOT NULL' end as A, substring(@name,-6,12) as B
and you will see the result:
A B
-------- ------------
NOT NULL Chris
(1 row(s) affected)
Despite what is shown in 2008 BOL
Maybe the author of the question uses some "secret special" BOL 😉
I use the following link: http://msdn.microsoft.com/en-us/library/ms187748.aspx, and what I see there:
SUBSTRING ( value_expression ,start_expression , length_expression )
...
If length_expression is negative, an error is generated and the statement is terminated.
So, length_expression cannot be negative, but the "-6" from the question is start_expression.
the code ... does not return the whole value expression when the sum of the start and length values are greater than the length of the variable
Just a little detail from BOL:
the whole value expression beginning at start_expression is returned
😉