Solved

CHARINDEX with start_location

Posted on 2010-09-17
4
383 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
  • 2
  • 2
4 Comments
 
LVL 92

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 92

Accepted Solution

by:
Patrick Matthews earned 250 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now