Use of CHARINDEX Function in SQL

Use of CHARINDEX Function in SQL:

(1) “CHARINDEX” function is used to get the position of Character from a string.

(2) Let’s take an example to get the position of ‘e’ from the Vendor Address field in the Vendor table as shown. Note: (i) This function performs a case-insensitive search and (ii) Gives first find position of the defined character (example: if we have to find the position of “E” in the string “America Export”, then it gives the position value of 3, not 9.)

(3) Select the database in the SQL server and click on the “New Query” button as shown.

Select the database in SQL server and click on the New Query

(4) After that new query editor opens as shown.

new query editor open in sql

(5) After doing the above steps, write a query in the editor, as shown.

sql charindex query

Source Code:

–//CHARINDEX get position of character form Vendor Address field
Select [No_] as [Vendor No.],[Name] as [Vendor Name],
CHARINDEX(‘E’,Name)as [Charcater Position Value from Vendor Name]
fromdbo.[CRONUS India Ltd_$Vendor$437dbf0e-84ff-417a-965d-ed2bb9650972] TB1
–//CHARINDEX get position of character form Vendor Address field

(6) Then Execute or Press F5 to run the query and see the result as shown.

execute charindex sql query

Use of CHAR function in SQL
How to Create Connection between Excel and SQL database
Use of IN operator in SQL
How to Install AL code extension in VS Editor
Getting Started with AL– Microsoft Docs

Leave a Reply