We are familiar with the like statement. For example, to find all users whose usernames contain "C", we can use mydatabase
Select * From Table1 where username like '% C %"
The following is another way to complete the above functions:
Use mydatabase
Select * From Table1 where charindex ('C', username)> 0
In theory, this method has one more judgment statement than the previous method, that is,> 0, but this judgment process is the fastest, I believe that more than 80% of the operations are spent on searching strings and other operations, so using the charindex function is no big deal. This method also has advantages, that is, %, | and so on can be used directly in this charindex in characters not directly searched with like, as shown below:
Use mydatabase
Select * From Table1 where charindex ('%', username)> 0
You can also write it as follows:
Use mydatabase
Select * From Table1 where charindex (char (37), username)> 0
ASCII characters are %