I want to use substring
in SQL server to capture a string between a specific text string and the following char(10)
. The problem is that there are several occurrences of char(10)
in the complete string so I need some code to localize the first char(10)
after my specific string. Using the code below results in an error due to a negative value (first char(10) occurs prior to the my specific string
).
SELECT SUBSTRING(col, LEN(LEFT(col, CHARINDEX ('my specific string', col))) + 1, LEN(col) - LEN(LEFT(col,
CHARINDEX ('my specific string', col))) - LEN(RIGHT(col, LEN(col) - CHARINDEX (char(10), col))) - 1);
Error: Invalid length parameter passed to the LEFT or SUBSTRING function.