Hi @mo boy
At the first glance of this issue, this may cause by your source data.
Check this sample: select substring('abc',1,charindex('-','abc') - 2) which will receive same error message.
CHARINDEX will return 0 if no '-' are in the string and then you look for a substring of **0 - 2 = -2 ** length.
Therefore, you'd better check if there is any special data in the source data table that causes the function to return a negative number. You can split these functions such as charindex to check which one returns a negative value.
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.