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.
(4) After that new query editor opens as shown.
(5) After doing the above steps, write a query in the editor, as shown.
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.