0

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'

4
  • Why are you not sure if this works ? Have you run it ? Commented Jun 11, 2020 at 13:53
  • 1
    If you are certain about your leading and lagging characters then use attr LIKE 'ABC%DEF' for anything in between including spaces. Commented Jun 11, 2020 at 13:58
  • Okay so a single % will do the job? Thanks! I am unsure because I am preparing some queries atm for tables that dont exist rn ^^ Commented Jun 11, 2020 at 14:03
  • You can run your test using passing some values. Commented Jun 11, 2020 at 14:17

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.