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
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
6 Comments
Shine
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.
heximal
you may compose your pattern as '%'+Name - this matches your purpose
Shine
Could u please help me out doing this.
heximal
look at the example i've added to my answer.
Shine
I think i need to write patindex('%'+@pat+'%',Login) is it.?
|