1

I tried using Instr for this, but didn't work, so I found the supposed to be equivalent using PatIndex and CharIndex, however, I'm having an issue here when I run this:

SELECT PATINDEX(`http://www.stackoverflow.com`,'%.com%')

This returns 0


SELECT CHARINDEX(`http://www.stackoverflow.com`,'%.com%')

This returns 0


SELECT PATINDEX(`http://www.stackoverflow.com`,'.com')

This returns 0


SELECT CHARINDEX(`http://www.stackoverflow.com`,'.com')

This returns 0


How do I get this to work like InStr ?

If my calculation is correct, it should return 25 instead of 0, anyone know why it's not?

2 Answers 2

3

You've got it reversed.

select patindex('%.com%', 'http://www.stackoverflow.com');
select charindex('.com', 'http://www.stackoverflow.com');
Sign up to request clarification or add additional context in comments.

Comments

1

Be careful while using those functions in computed column functions. Because they are non-deterministic.

https://technet.microsoft.com/en-us/library/aa214775(v=sql.80).aspx

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.