-1

currently I'm making something.

using (var IDatabaseQuery = Lightningbolt.GetDatabaseManager().CreateQueryObject())
        {
            IDatabaseQuery.SetQuery("SELECT * FROM catalogue_baseitems WHERE name LIKE '%hc2_%' OR name LIKE '%hc3_';");
            data = IDatabaseQuery.FetchTable();
        }

That's what I use, I want to get all the items beginning with hc2_ and hc3_, however, I only get the items starting with hc2_. In the SQL contains also items starting with hc3_ but it doesn't show while executing the query. What do I wrong?

3 Answers 3

3

If you want items beginning with hc2_ or hc3_, you need to make two changes:

  1. Don't use the % at the beginning, and
  2. Escape the underscore because it masks to "any one character"

Try something like this:

SELECT * FROM catalogue_baseitems WHERE name LIKE 'hc2\_%' OR name LIKE 'hc3\_%'

Note that %hc2_% will match any of the following examples:

  • abchc2X (because of the leading % and the underscore will match the X)
  • hc23 (because underscore will match the 3)
  • ... and so on
Sign up to request clarification or add additional context in comments.

Comments

1

You are missing the second percent sign: '%hc3_%'

1 Comment

Thanks, that worked well. I did some dirty quick work so I must've forgotten the second percent sign.
1

You want result which contains hc2_ and hc3_ at the beginning then you need to use clause like this 'hc2_%' or hc3_%.

You are getting results for hc2_ because you are using '%hc2_%', this return any string which contains hc2_ anywhere in the string.

Change your query to this

IDatabaseQuery.SetQuery("SELECT * FROM catalogue_baseitems WHERE name LIKE 'hc2\_%' OR name LIKE 'hc3\_%';");

and don't forgot about underscore(_), this is a wildcard character.

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.