I'm trying to understand this piece of code. The part that is confusing me is the Else Case. I understand that the Substring function extract data from an expression, and the CharIndex returns a number, which i think represents the length of characters that the Substring function will output.
1. What is the -1 doing to the Charindex function.
2. What does the code do to this value in the table. What would the 90A- become after the code has been executed. And why?:
WHEN CHARINDEX('-',RSPF.RSPF_PROD_N) = 0 THEN LTRIM(RTRIM(RSPF.RSPF_PROD_N))
WHEN RSPF.RSPF_R_OR_S = 'R' THEN SUBSTRING(LTRIM(RTRIM(RSPF.RSPF_PROD_N)), 1, CHARINDEX('-',LTRIM(RTRIM(RSPF.RSPF_PROD_N)))-1)
END AS PRODUCT_NUM