?
Solved

CHARINDEX with start_location

Posted on 2010-09-17
4
Medium Priority
?
432 Views
Last Modified: 2012-05-10
do not understand why the result is the same if the difference is in the parameter start_location
charINDEX.jpg
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 33705186
Because all the start position parameter does is tell SQL Server, "ignore any instances of the substring that start before ".
0
 

Author Comment

by:enrique_aeo
ID: 33705280
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
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1000 total points
ID: 33705307
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
 

Author Closing Comment

by:enrique_aeo
ID: 33705344
your example is much better. Thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question