SQL Server > Query

Wild card characters in SQL Server

How to use wild card characters in SQL Server database query?


One use of wild characters we have already seen in retrieving all records from the database. (SELECT * FROM PersonalDetails). It can also be used to retrieve records that starts with or ends with or contains a particular characters. In the WHERE clause, these characters must follow by LIKE clause.

SELECT * FROM PersonalDetails
WHERE FirstName LIKE 'Su%'

SELECT * FROM PersonalDetails
WHERE FirstName LIKE '%eo'

SELECT * FROM PersonalDetails
WHERE FirstName LIKE '%e%'

The 1st SELECT statement returns all records from the table whose FirstName starts wtih “Su” followed by any characters.

The 2nd SELECT statement returns all records from the table whose FirstName ends with “eo” preceded with any characters.

The 3rd SELECT statement returns all records from the table whose FirstName contains “e” anywhere in the FirstName column value.

 Views: 7576 | Post Order: 53



Write for us






Hosting Recommendations