whadiz.com: What is?
Search Articles:     Home | About | Tools | Contact Us
You are here: Home > Databases > Sql Server > charindex
Games
Board Games
Online Games
Databases
Sql Server
Programming
Visual C# in ASP.Net
JavaScript
Humor
Satire
Web Design
Html

Clever Facts Section

What is Charindex? | Find position of character | Sql Server Charindex | Charindex in Sql Server

What is charindex?

Sql charindex is a sql server function that indicates the first position of a character or a character string within another character string. When a character or character string is found with sql charindex, the starting position is indicated with a non-zero positive integer value. If a character or character string is not found with charindex, a zero integer value is returned. charindex's starting position is 1, unlike other index search functions that would normally return 0 as the first position. 

How does charindex work?

charindex ( expression1 , expression2 [ , start_location ] )

expression1 is the string of characters to look for in expression2. start_location indicates the starting index where charindex should start looking for expression1 in expression2.

Examples of how to use charindex

charindex('test', 'This is for testing.')

When executing charindex as above, it would return 13 as the result. charindex looks for "test" in the character string "This is for testing."

charindex('test', 'testing')

When executing charindex as above, it would return 1 as the result. This is the very first position when working with charindex.

charindex('test', 'The searchstring is not here.')

When executing charindex as above, it would return 0 as the result. charindex looks for "test" in "The searchstring is not here." and cannot find "test".

charindex can be combined with a select statement as follows:

SELECT charindex(' ',colname)
FROM tablename;

This would result in the first position of a space that charindex comes across.

Link to this article:

Browse some more: Next Article | Next Fact | More Sql Server Articles | More Clever Facts


Copyright © 2021 whadiz.com. All rights reserved.
whadiz.com: What is Charindex? | Find first position of character | Sql Server Charindex | Sql Charindex | Charindex in Sql Server
Home of the answer "what is"