LIKE Operator

  • Hi,

    I want to display list of tables , which having "_" in the part of table name?

    Thanks.

    RR

  • select * from sysobjects where xtype='U' and name like '%_%'

  • laurie-789651 (8/14/2013)


    select * from sysobjects where xtype='U' and name like '%_%'

    That won't work because "_" is itself a wildcard character. Look up escape characters in Books Online.

    John

  • Good point.

    How about

    select * from sysobjects where xtype='U' and name like '%[_]%

    or

    select * from sysobjects where xtype='U' and name like '%[_][_]%

    for two underlines..

  • That seems to work... as long as you remember to close your quotes!

    By the way, sysobjects is there for backward compatibility only. You should use sys.objects, sys.tables or INFORMATION_SCHEMA.TABLES instead.

    John

  • Thanks Laurie...

    it is working fine....

  • you can also try using ESCAPE -

    SELECT s.name

    FROM sys.objects s

    WHERE

    s.type= 'U'

    AND s.name LIKE '%!_%' ESCAPE '!'

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 7 posts - 1 through 6 (of 6 total)

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