Well - this code is going to do something a bit different than what Steve outlined, depending on the actual data in the PortionKey column. If there are leading blanks - this code will return the last nn characters where nn is the number of leading blanks.
select case WHEN Po.PortionKey LIKE '%[_]%'
LEN(LTRIM(RTRIM(Po.PortionKey)))) end as modifiedportionkey,
case WHEN Po.PortionKey LIKE '%[_]%'
THEN 'True' else 'False' end as IsTrueCondition,
from (values (' blah [_] blah '),
(' blah blah blah ')) Po(PortionKey);
So - with one leading blank the value returned will be 'h'. The last character in the string prior to the trailing blanks which are removed for the substring. If there are 2 leading blanks the value returned would be 'ah'.
To understand why the code was written this way - you need to evaluate the data in the PortionKey and the value being returned from this statement in the query where it is utilized. For example, is the underscore always the last character in the PortionKey - or can that character be anywhere in the string?
How is the returned column utilized by the caller? That will also help determine why the code is built this way - which can then lead to options to optimize the code (if needed).