I am using SQL Server 2012. I have this statement in my query
SELECT * FROM table1 PC
JOIN table2 t2
ON PC.ID = t2.ID
AND
(
RIGHT
(
PC.C_PRODUCT_ID,
(DATALENGTH(PC.C_PRODUCT_ID) - (DATALENGTH(PC.C_PRODUCT_ID) - CHARINDEX(REVERSE('*'),
REVERSE(PC.C_PRODUCT_ID)))-1)
)
) = REPLACE(T2.COMP_PROD_ID,' ','')
and it throws an error
Msg 536, Level 16, State 4, Line 2
Invalid length parameter passed to the RIGHT function.
I took a few examples and see that a positive value is being passed on to the RIGHT
function.
An example of C_PRODUCT_ID
here in my case
- C_PRODUCT_ID = '3-12*LV431536'
- Reverse of C_PRODUCT_ID = '635134VL*21-3'
Therefore, according to the above statement
26 – (26- 9) -1
26- 17 -1
9 -1
8
its RIGHT(3-12*LV431536,8) which is LV431536 and this value exists in T2.COMP_PROD_ID.
I hope my question is clear and doesn't deserves to be on hold now.