Reputation: 49
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!
Upvotes: 3
Views: 3178
Reputation: 133400
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%';
Upvotes: 2
Reputation: 6586
If the data type is number then you can try the following
Select ID, NAME
From Table1
Where to_char(ID) LIKE '888%'
Or to_char(ID) LIKE '999%';
Upvotes: 1