|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, April 08, 2011 8:55 AM
Points: 274,
Visits: 149
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:45 AM
Points: 298,
Visits: 77
|
|
Refer this link http://www.ianywhere.com/developer/product_manuals/sqlanywhere/0902/en/html/dbrfen9/00000293.htm
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:27 PM
Points: 408,
Visits: 681
|
|
Took a guess and got it wrong, but... Ran this on 2005 and A is not actually NULL, its an empty string. Maybe its NULL on 2008?
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: 2 days ago @ 1:32 AM
Points: 3,187,
Visits: 4,140
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:38 AM
Points: 1,101,
Visits: 1,192
|
|
Just a little mistake, empty string and null. But to tell the truth, I was confused, because I know the first expression returns empty string and not a null...
See, understand, learn, try, use efficient © Dr.Plch
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Friday, November 09, 2012 2:48 PM
Points: 493,
Visits: 636
|
|
| Even though A is empty string versus Null the answer is still obvious given that it is multiple choice. In other words it was obvious that the author had just made a mistake between empty/null since options A and C were so far off.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, March 27, 2013 9:02 AM
Points: 1,046,
Visits: 573
|
|
I chose the one closest to the answer and I seem to have got it right. Hihahhhhh
What you don't know won't hurt you but what you know will make you plan to know better
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Monday, November 26, 2012 9:08 AM
Points: 310,
Visits: 243
|
|
| Can some one explains how it returns 'chris' when the start value is -6 and length is 12.
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Saturday, April 06, 2013 12:20 AM
Points: 649,
Visits: 263
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, February 12, 2010 8:31 AM
Points: 29,
Visits: 37
|
|
If you think of it sort of as a number line, the name "Christopher" would occupy spots 1 thru 11 of the line. The expression is askiing you to look at spots -6 thru 5. This is 12 spots because of the number zero. The first 7 spots (-6 thru 0) we're asked to look at don't correspond to any characters in the name and don't return any characters. But the last 5 spots correspond to spots 1 thru 5 of the number line and those spots are occupied by the characters "Chris".
This is perhaps a clumsy example, but it seems to work.
|
|
|
|