The error 'Invalid length parameter passed to the SUBSTRING function' occurs in SQL. The code with the problem is below.
RTRIM(Substring('000000000000000',1,15 - LEN(pid.Person_Identifier_Value)) + pid.Person_Identifier_Value) AS 'Consumer Data ID'
Person_Idendifier_Value is not null for any of the records. The length of each value is less than 15. 15 - the length is a positive number in all cases. The SQL does multiple joins. I thought of building a temp table and getting the values from there. I do not want to add too much overhead to the SQL.