Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CHARINDEX with start_location

Posted on 2010-09-17
4
Medium Priority
?
438 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

618 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