0% found this document useful (0 votes)
14 views

Working With SQL Server

The document discusses two SQL Server string functions: CHARINDEX() finds the position of a substring within a string. It takes a substring, string, and optional starting position as parameters. If the starting position is provided, it begins searching from that index instead of the first character. SUBSTRING() returns part of an expression string. It takes the expression, a start index, and length. The start index specifies where to start extracting characters and the length specifies how many characters to return.

Uploaded by

Vidya Sagar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Working With SQL Server

The document discusses two SQL Server string functions: CHARINDEX() finds the position of a substring within a string. It takes a substring, string, and optional starting position as parameters. If the starting position is provided, it begins searching from that index instead of the first character. SUBSTRING() returns part of an expression string. It takes the expression, a start index, and length. The start index specifies where to start extracting characters and the length specifies how many characters to return.

Uploaded by

Vidya Sagar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Working with CHARINDEX() funciton in sql server 2008

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 substrings 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.


What Is SUBSTRING In SQL Server, Example Of
SUBSTRING Function In SQL
SUBSTRING function returns part of a character, binary, text, or image expression. We use
SUBSTRING to split the string and get only some part of it.
Syntax:- SUBSTRING ( expression , start , length )
1. Expression:- Is a character string, binary string, text, image, a column, or an expression that
includes a column. Do not use expressions that include aggregate functions.
2. Start:- Is an integer that specifies where the substring begins.
3. Length:-Is a positive integer that specifies how many characters or bytes of
the expression will be returned. If length is negative, an error is returned.
Example:-

You might also like