0

I have the following query:

SELECT 
    substring(Content, charindex(N'<img src=''http://tex.', Content), 
                       charindex(N'class=''latex-formula''>', Content)+22) as Img
FROM 
    [Scyk].[dbo].[Posts]
WHERE 
    content LIKE '%<img src=''http://tex.%'

Now I would expect it to give me all <img> tags that I have in database. But instead, it returns something like this:

<img src='http://tex.z-dn.net/?f=x%3Dlog_%7B%5Csqrt%7B2%7D%7D64' id='TexFormula' onerror="texError(this)" title='x=log_{\sqrt{2}}64' alt='x=log_{\sqrt{2}}64' align='absmiddle' class='latex-formula'> to:</p><p>a)

Where the end of the string ends randomly, it can be few characters too many, or it can be plenty characters too many. What is wrong in my query?

2 Answers 2

3

I think the third argument to substring() is the length of the section you want to extract, not the end index. you would have to subtract the first charindex from the second to get the length.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh. I think you are right, will go check it right away, thanks!
0

The third argument is the length not the index.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.