---
title: "How to Check if a String Contains a Substring in Sql Server"  
description: "In this article I wil explain how to check a specific word or characters in a given statement in SQL Server using CHARINDEX function or SQL Server che"  
author: "Amit Kumar"  
published: 2017-04-28  
updated: 2020-05-28  
canonical: https://www.mindstick.com/articles/12309/how-to-check-if-a-string-contains-a-substring-in-sql-server  
category: "sql server reporting services"  
tags: ["sql server"]  
reading_time: 2 minutes  

---

# How to Check if a String Contains a Substring in Sql Server

In this article I wil explain how to check a specific word or [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) in a given [statement in SQL](https://www.mindstick.com/forum/33706/what-is-the-difference-between-having-clause-and-group-by-statement-in-sql-server) Server using [CHARINDEX function](https://www.mindstick.com/forum/156817/what-is-the-difference-between-substring-and-charindex-function-in-the-sql-server) or [SQL Server](https://www.mindstick.com/articles/34/create-table-in-microsoft-sql-server) check if [string contains](https://www.mindstick.com/forum/159365/how-to-check-if-a-string-contains-letters-only-in-sql) specific substring with CHARINDEX function. Alternative to CHARINDEX() is using the LIKE predicate

##### Method 1: Using CHARINDEX() function

**CHARINDEX():** This function is used to search for specific word or substring in overall [string and returns](https://www.mindstick.com/forum/157802/write-a-javascript-program-that-takes-a-string-and-returns-the-longest-word-length) its starting position of match In case if no word found then it will return 0 (zero).\
Let us understand this with examples.\

##### Syntax:

1. CHARINDEX ( SearchString,WholeString[ , startlocation ] )

Example:

1. Declare @mainString nvarchar(100)='Amit Kumar Yadav'
2. ---Check here @mainString contains Amit or not, if it contains then retrun greater than 0 then print Find otherwise Not Find
3. if CHARINDEX('Amit',@mainString) > 0
4. begin
5. select 'Find' As Result
6. end
7. else
8. select 'Not Find' As Result

Output: ![How to Check if a String Contains a Substring in Sql Server](https://www.mindstick.com/mindstickarticle/fe49242d-9b21-47d8-bad1-acfc17455f00/images/05b6c7a4-380e-485d-a06b-9dd168aa68f5.png) Method 2: Using LIKE Predicate

1. DECLARE @WholeString VARCHAR(50)
2. DECLARE @ExpressionToFind VARCHAR(50)
3. SET @WholeString = 'Amit Kumar Yadav'
4. SET @ExpressionToFind = 'Kumar'
5.
6. IF @WholeString LIKE '%' + @ExpressionToFind + '%'
7. PRINT 'Yes it is find'
8. ELSE
9. PRINT 'It doesn''t find'

##### Output :

![How to Check if a String Contains a Substring in Sql Server](https://www.mindstick.com/mindstickarticle/fe49242d-9b21-47d8-bad1-acfc17455f00/images/004ff243-dc3c-4d79-8adf-d7c164ff3dac.png)

---

Original Source: https://www.mindstick.com/articles/12309/how-to-check-if-a-string-contains-a-substring-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
