0

I have written a function which takes the Name as input and returns Suffix. I want to return the position of suffix in a name with a function. How can i do that. Could any one please help me doing it.

1 Answer 1

1

there is no need to create special function fot this. it already exists in t-sql. its name is PATINDEX Example:

declare @pat varchar(128)
set @pat = '_suf'
select login, Patindex('%'+@pat, login) as suffix_index from clients 
Sign up to request clarification or add additional context in comments.

6 Comments

The problem with using Patindex is that, if the name has sililar pattren twice then it will find the position of first occered position in word. Example: Advin Dovin DO . patindex returns 6 not 13.
you may compose your pattern as '%'+Name - this matches your purpose
Could u please help me out doing this.
look at the example i've added to my answer.
I think i need to write patindex('%'+@pat+'%',Login) is it.?
|

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.