The code looks for the string 'Director :' in @actTextDisplay. It then looks to see if a period ('.') appears after that string. If so, then it extracts the part of the string after 'Director: ' and before the period. If there is not a period, then it uses the entire rest of the string after 'Director:'.
It can be simplified to this with the same result:
SET @actTextDisplay_DirectorIndex = CHARINDEX('Director: ', @actTextDisplay)
IF @actTextDisplay_DirectorIndex > 0
SET @actTextDisplay_DirectorLength = CHARINDEX('.', @actTextDisplay + '.',
@actTextDisplay_DirectorIndex) - @actTextDisplay_Directorindex
The CHARINDEX('.', ...) finds the byte location of the period after the 'Director: ' string (note that I add a '.' to the string so that a '.' will always be found, eliminating the need for the IF/ELSE in the original code) . Variable @actTextDisplay_DirectorIndex already contains the byte where 'Director: ' starts. To get the length of the string from 'Director: ' to the dot/end of string, we simply subtract the two. For example:
--23456789!123456789@123456789#123456789$123456789%123456789^
'any old text Director: director_id_goes_here. and some more text'
Starts in byte 14 (Director:), ends in byte 45(.), 45 - 14 = len of 31
Btw, the code:
if len(ISNULL(@referToDirectID,'')) = 36
BEGIN
SELECT @txt_Refer_to_recipient_id = CONVERT(VARCHAR(36),ORR.uniq_id)
FROM Table A
is still needed, of course, I just adjusted the code before that, that calc'd the length.