Wildcard Search in SQL Query

There are times when you don’t have a specific value to find but you might have to use the general pattern and want to get the records that match that pattern.

You can use the LIKE clause in this case and use the the wildcards for the search expression.

You can use the wild characters like % , _ , [..] , [^..] where % represents the string with zero or more characters. The _ represents the single character. The [] can be used to specify the list of characters like . [^..] represents the single character from the list that is present.

For example , you want to get the TOP 1000 department records whose name starts with E. Your query will look like the one below.

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 DepartmentID
      ,Name
      ,GroupName
      ,ModifiedDate
  FROM Department
  WHERE  Name LIKE 'E%';

 

image

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


x

Interesting BlogPosts to read

How to insert bullets in to cells in Microsoft Excel ?
Do you want to insert bullets in cells of Microsoft Excel?. Here's how you can do it. How to insert ...
How to resize print area and fit to Single page in Excel 2016 ?
When you try to print a worksheet in Microsoft Excel 2016 , you may notice that the content might ov...
How to find the Created and Last Modified time in Microsoft Excel ?
You can easily find out the exact date and time when the excel workbook was created and modified usi...