Search code examples
sqlsql-likesap-iq

How to skip the "_" in like %% clausure , Sybase IQ


Task: find all the Views that start with "vf_"

The code should be:

 select * from systable where table_type = 'VIEW' and table_name like 'vf_%'

The Problem is that the database use the " _ " like a joker , that means that in the " _ " could come every sign.

thats why is returning me

vf_
vfa
vfg
..
..

How could I say to database that i just want the views that start for "vf_" ?


Solution

  • In addition to Gordon's suggestion of using an escape character ...

    You can search for the underscore as a string (as opposed to a wildcard character) by placing the underscore inside a pair of square brackets, eg:

    select * from systable where table_type = 'VIEW' and table_name like 'vf[_]%'