Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Working with CHARINDEX() funciton in sql server 2008.

Author: Shehzad Hemani

In this simple article you will learn that how to work with CHARINDEX () function in SQL Server using PL/SQL.

 CHARINDEX () is the one of the most commonly used functions of SQL Server. It is used to find out the position of any specific substring in a given string. It takes three parameters; first is the substring whose position is to be find, second is the string in which the substring’s position has to be find and third parameter is the starting location to find out the substring. Third parameter is the optional one. When it is given, the search of the substring will be then started from the index greater than the start location.

 

Syntax:

CHARINDEX (substring, superstring, start_location)

 

It can be used only with the SELECT command. The syntax for using it with SELECT command

 

SELECT

CHARINDEX (substring, superstring, start_location)

AS

String Position

 

Example:

 

SELECT

CHARINDEX (‘is’, ‘It is an example’)

AS

String Position

 

 Output:

 

String Position

-------------

4

 

 

 

Another example to show, if start location parameter is given them what would be result.

 

Example:

 

SELECT

CHARINDEX (‘the’, ‘the example to obtain the result’, 10)

AS

String Position

 

 Output:

 

String Position

-------------

23

 

Here, the position of the keyword is given which is greater than the start location.

And, if in case, the given substring is not found in the given string, it will give 0 as a result.

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Working with REVERSE () function in SQL Server 2008 using PL/SQL.

Disclaimer - Privacy
© 2002-2017 DevASP.net