Twitter

Follow SQLQuill on Twitter

Subscribe

MN Pass

TSQL Tip O’ the Week – 7/12/11 – Wildcards

This weeks tip:

I use wildcards and the “LIKE” operator in my TSQL all the time – a lot of the time to find table names, column names etc.

Select OBJECT_NAME (OBJECT_ID),
NAME
from sys.columns
where name like '%file%'

Ninety eight percent of the time, I use the %.  The other two percent, I need to look up the exact syntax.  Well, here’s a quick reference for you:

Wild Card Description
% Any string of characters i.e.  %ID%
_ Any single character i.e.  _ndy
[] Any single single character in a range specified or set i.e.  [A-L]  OR [ABC]
[^] Any single single character not in a range specified or set i.e.  [^A-L]  OR [^ABC]

Sometimes an issue comes up where you need to search for the actual wildcard character, for more info on that, check out the section titled “Using Wildcard Characters As Literals” from the MSD article on LIKE.

Here are some related posts from the intraweb:

Previous Tips O’ the Week

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>