![]() ![]() The execution of the above query statement gives the following output with 0 as return position, which means that the word with value “well” was not found in the original string “170, Mountain Villa, Prince Edward Parade, Cross Road, Hunters Hill” – Let us now search for some other string in the same original string, say “well” using the CHARINDEX function and observe the output of the following query – SELECT CHARINDEX('well', '170, Mountain Villa, Prince Edward Parade, Cross Road, Hunters Hill') The execution of the above query statement gives the following output – Our example searches for the “hill” word in the string using the following query statement – SELECT CHARINDEX('hill', '170, Mountain Villa, Prince Edward Parade, Cross Road, Hunters Hill') If the CHARINDEX function returns a non-zero positive value, then the key which we are trying to search has been found at the position that is retrieved from the function else, the search string is absent. Let us now use the CHARINDEX function to find out whether a particular string has a “hill” word in it and search for it. The execution of the above query statement gives the following output containing two records which have “word” in their meaning – SELECT * FROM dictionary WHERE meaning LIKE "%word%" For this, we will use the following query containing the LIKE function. Now, we have to search for the records that contain the “word” string in their column values of meaning. Let us consider the example by using a table named dictionary that contains the following records – SELECT * FROM dictionary Further, PATINDEX, CHARINDEX functions help us retrieve the string’s position that we are trying to search in other strings or character-based columns and returns the index if string found successfully. We can use the LIKE function to search for the words that begin with, end with, or contain certain characters that we have specified. String search using PATINDEX, CHARINDEX, and LIKE functions ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |