0xDr0id
0xDr0id

Reputation: 319

How to have a SQLite query with a variable part?

Hi I am trying to create a query for SQLite which has a variable part in it. By variable I mean that a certain part within the string can possibly contain a variable but also an empy value

I tried this but I am not sure whether this works.

SELECT * FROM table WHERE attr LIKE 'ABC% %DEF'

Upvotes: 0

Views: 23

Answers (1)

VTi
VTi

Reputation: 1319

Adding onto my comment, check the below code to test your values.

SELECT CASE WHEN 'ABC G DEF' LIKE 'ABC%DEF'
            THEN 1
            ELSE 0 END as test_space,
       CASE WHEN 'ABCGGGDEF' LIKE 'ABC%DEF'
            THEN 1
            ELSE 0 END AS test_all

Upvotes: 1

Related Questions