• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

CHARINDEX with start_location

do not understand why the result is the same if the difference is in the parameter start_location
charINDEX.jpg
0
enrique_aeo
Asked:
enrique_aeo
  • 2
  • 2
1 Solution
 
Patrick MatthewsCommented:
Because all the start position parameter does is tell SQL Server, "ignore any instances of the substring that start before ".
0
 
enrique_aeoAuthor Commented:
i do not understand very well
i confuse because msdn tell
Is an integer or bigint expression at which the search starts. If start_location is not specified, is a negative number, or is 0, the search starts at the beginning of expression2.
0
 
Patrick MatthewsCommented:
Which is the same thing that I said, really :)By passing a 5 for the 'start at' parameter, you are not shortening the string.  You are simply stating where the search should start.  The starting character position for the found substring is still measured relative to the beginning.For example:DECLARE @str varchar(100)SET @str = 'This foo is a test foo'SELECT CHARINDEX('foo', @str)       /* returns 6 */SELECT CHARINDEX('foo', @str, 7)   /* returns 20 */That second 'foo' starts at position 20; by passing 7 for the 'start at' parameter, we ignore the 'foo' that started at position 6.
0
 
enrique_aeoAuthor Commented:
your example is much better. Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now