List all tables with a certain string

  • Hi,

    I want to list al tables that contains only _ar_ in the name (archive tables)

    I have tried the following script

    Select name from sys.tables where name like '%_ar_%'

    but when i get the result i also see tables like abc_yard_abc and i only want to have tables like abc_ar_abc

     

  • Your problem here is that the underscore character is itself a wildcard in T-SQL, matching any single character. That explains the results you are seeing.

    The solution is to ESCAPE the wildcard. Something (rather inelegant) like this (untested):

    Select name 
    from sys.tables
    where name like '%|_ar|_%' ESCAPE '|';

    • This reply was modified 4 years, 8 months ago by Phil Parkin.

  • Thanks Phil it seems to work !

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply