T-SQL String Functions: difference between using Left/Right and Substring and strange behaviour

Posted by TheObserver on Stack Overflow See other posts from Stack Overflow or by TheObserver
Published on 2010-04-01T01:26:48Z Indexed on 2010/04/01 1:33 UTC
Read the original article Hit count: 336

I am using SQL Server 2008 & 2005 (Express). I'm trying to extract part of an alpha numeric string from a varchar field.

RIGHT(str_field,3) yields null values but substring(str_field, len(str_field)-2, len(str_field)) gives the right value. left(str_field,7) gives the expected values. What gives? I would have thought that RIGHT(str_field,3) and substring(str_field, len(str_field)-2, len(str_field)) are equivalent expressions.

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server-2008