It is well known to mention like statements, for example, to find all users with "C" in their username, we can use the MyDatabase select * FROM table1 where username '%c% '
Here's another way to write the above function:use mydatabase
select * from table1 where charindex('c',username)>0
This method in theory than the previous method more than a judgment statement, that is, >0, but this process is the fastest, I believe that more than 80% of the operations are spent looking for strings and other operations, so the use of charindex function is not a big deal. This method also has the advantage, that is to%,| and so on can not be directly with like to find characters in the use of this charindex directly, as follows:
use mydatabase
select * from table1 where charindex('%',username)>0
You can also write:
use mydatabase
select * from table1 where charindex(char(37),username)>0
The ASCII character is%