Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Querying a table name that contains underscore.

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hello, All.

I have a query where I am looking for tables that end in _AM.

Code:
SELECT sch.[name] AS SchemaName, tab.[name] AS TableName
  FROM sys.Tables AS tab
  JOIN sys.Schemas AS sch
    ON tab.schema_id = sch.schema_id
 WHERE tab.[name] LIKE '%_AM'
   AND sch.[name] = 'dbo'

I get back:

dbo Inspection_7152014_112102_AM
dbo Program
dbo Inspection_7152014_113629_AM
.
.
.
etc.

Is there a way to get this query to recognize the underscore?
I cannot perform my intended operation on the 'Program' table.
I am using SQL Server 2008.

Thanks, Everyone.
Patrick
 
From the BOL:

You can use the wildcard pattern matching characters as literal characters. To use a wildcard character as a literal character, enclose the wildcard character in brackets.

so LIKE '%[_]AM' will work.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
WHERE Right(TableName,3) = '_AM' ?

Beir bua agus beannacht!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top