Why does PATINDEX('%n%','nguyen')
return value 6, not the first occurrence, but PATINDEX('%n%','nathan')
return a value of 1, the first occurrence?
Asked
Active
Viewed 176 times
0

Andrew
- 4,953
- 15
- 40
- 58
-
check your data, I get return value 1 for both – JSR Sep 16 '14 at 16:00
-
are you missing the trailing % in the first call? That would cause it to return 6. PATINDEX('%n', 'nguyen') – JSR Sep 16 '14 at 16:01
-
Sorry, I'm Vietnamese, my foreign language not very good! I was try again with code: PATINDEX('%n%','nguyen'), but it's return 6. I do not create Database, I just execute code: Select PATINDEX('%n%','nguyen'), how to show my image in my comment? Thanks – Lương Phạm Thái Huy Sep 16 '14 at 17:44
-
I think you have a problem with your search term. PATINDEX('%n%', 'nguyen') will return 1 PATINDEX('%n', 'nguyen') will return 6, notice that the second example is missing a % – JSR Sep 19 '14 at 17:31
-
@JSR: please view this image: http://postimg.org/image/xzyreone7/ – Lương Phạm Thái Huy Sep 19 '14 at 18:18