---
title: "What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?"  
description: "What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?"  
author: "Ashutosh Kumar Verma"  
published: 2021-11-10  
updated: 2021-11-10  
canonical: https://www.mindstick.com/forum/156817/what-is-the-difference-between-substring-and-charindex-function-in-the-sql-server  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 2 minutes  

---

# What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between [SUBSTRING](https://www.mindstick.com/articles/12309/how-to-check-if-a-string-contains-a-substring-in-sql-server) and CHARINDEX [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) in the [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server)?

## Replies

### Reply by Steilla Mitchel

**SUBSTRING() in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database):**

The SUBSTRING() function is returns a part of given string or we can say this function is extract some characters from given string.

Syntax – SUBSTRING(String, start, Length);

Example-

![What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?](https://www.mindstick.com/mindstickforums/f0e59eeb-d0ce-4729-a805-222cbe5601e1/images/3c9dc2bc-650f-4c77-b996-82f28138a1bc.png)

![What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?](https://www.mindstick.com/mindstickforums/f0e59eeb-d0ce-4729-a805-222cbe5601e1/images/3b6d70c5-995c-442d-9c25-b21f63c3711a.png)

## CHARINDEX() in SQL:

CHARINDEX() function is searches for a substring from String and returns the position or index number of particular substring from given String. If substring is not found then it returns 0.

Syntax- CHARINDEX(substring, string, start);

Start is optional in CHARINDEX() function.

Example-

![What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?](https://www.mindstick.com/mindstickforums/f0e59eeb-d0ce-4729-a805-222cbe5601e1/images/24879c78-8a1a-4eea-9ec0-4c29b1447b52.png)

![What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?](https://www.mindstick.com/mindstickforums/f0e59eeb-d0ce-4729-a805-222cbe5601e1/images/42d6863d-953b-4b4d-add9-91feab492b58.png)

In the following SQL statement the start number is provide where the searching is start. By default the starting position is 1.

![What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?](https://www.mindstick.com/mindstickforums/f0e59eeb-d0ce-4729-a805-222cbe5601e1/images/a414b689-9123-4a7a-8640-0d587a84f365.png)

![What is the difference between SUBSTRING and CHARINDEX function in the SQL Server?](https://www.mindstick.com/mindstickforums/f0e59eeb-d0ce-4729-a805-222cbe5601e1/images/f1832c84-224c-4360-a3cf-eaf7c51cca4b.png)\

\


---

Original Source: https://www.mindstick.com/forum/156817/what-is-the-difference-between-substring-and-charindex-function-in-the-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
