Search code examples
sqldb2sql-like

SQL like with multiple characters


I'm trying to perform some selects in DB2 SQL, using the LIKE command, specifically looking for values that start with certain multiple digits. I thought I was using the expression correctly, but I keep getting syntax errors and I'm not sure where I'm going wrong. Right now I've been trying:

Select ID, NAME
From Table1
Where ID LIKE '888%'
Or ID LIKE '999%';

Am I just using the wrong SQL for the environment? (This is polling DB2 for Zo/s) LIKE doesn't seem to work when I just try a single 8% or 9% either.

I appreciate any shared experience, thank you!


Solution

  • Be sure the id is not a number and if is a number then cast as char

    Select ID, NAME
    From Table1
    Where cast(ID as char(10)) LIKE '888%'
     Or cast(ID as char(10)) LIKE '999%';