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

SQL Server CHARINDEX() Function

The SQL Server CHARINDEX() function is used to search for a substring within a string and returns the position of the first occurrence. If the substring is not found, it returns 0, and the search is case-insensitive. The function can also start searching from a specified position in the string.

Uploaded by

soha.adel66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL Server CHARINDEX() Function

The SQL Server CHARINDEX() function is used to search for a substring within a string and returns the position of the first occurrence. If the substring is not found, it returns 0, and the search is case-insensitive. The function can also start searching from a specified position in the string.

Uploaded by

soha.adel66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1/22/25, 6:00 PM SQL Server CHARINDEX() Function

 Tutorials  Exercises  Certificates  Services  Search...  Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

SQL Server CHARINDEX() Function


❮ Previous ❮ SQL Server Functions Next ❯

Example Get your own SQL Server

Search for "t" in string "Customer", and return position:

SELECT CHARINDEX('t', 'Customer') AS MatchPosition;

Try it Yourself »

Definition and Usage


The CHARINDEX() function searches for a substring in a string, and returns the position.

https://www.w3schools.com/sql/func_sqlserver_charindex.asp 1/6
1/22/25, 6:00 PM SQL Server CHARINDEX() Function

If the substring is not found, this function returns 0.


 Tutorials  Exercises  Certificates  Services   Sign Up Log in
Note: This function performs a case-insensitive search.
HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

Syntax
CHARINDEX(substring, string, start)

Parameter Values
Parameter Description

substring Required. The substring to search for

string Required. The string to be searched

start Optional. The position where the search will start (if you do not want to start at the
beginning of string). The first position in string is 1

Technical Details
Works in: SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse,
Parallel Data Warehouse

More Examples

https://www.w3schools.com/sql/func_sqlserver_charindex.asp 2/6
1/22/25, 6:00 PM SQL Server CHARINDEX() Function

 Tutorials 
Example
Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R
Search for "OM" in string "Customer", and return position:

SELECT CHARINDEX('OM', 'Customer') AS MatchPosition;

Try it Yourself »

Example
Search for "mer" in string "Customer", and return position (start in position 3):

SELECT CHARINDEX('mer', 'Customer', 3) AS MatchPosition;

Try it Yourself »

❮ Previous ❮ SQL Server Functions Next ❯

Track your progress - it's free! Sign Up Log in

https://www.w3schools.com/sql/func_sqlserver_charindex.asp 3/6
1/22/25, 6:00 PM SQL Server CHARINDEX() Function

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

COLOR PICKER



https://www.w3schools.com/sql/func_sqlserver_charindex.asp 4/6
1/22/25, 6:00 PM SQL Server CHARINDEX() Function

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

 PLUS SPACES GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

Top Tutorials Top References


HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference
C++ Tutorial Angular Reference
jQuery Tutorial jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

https://www.w3schools.com/sql/func_sqlserver_charindex.asp 5/6
1/22/25, 6:00 PM SQL Server CHARINDEX() Function

 Tutorials  Exercises  Certificates  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT
   SQL   PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP R

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy
policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

https://www.w3schools.com/sql/func_sqlserver_charindex.asp 6/6

You might also like