Skip to content
Advertisement

Filter and Match Column on a List of Substrings

I am attempting to filter a table of user actions on a list of specific actions. For example, given the following data

I want all rows where the UserAction contains the strings “Account Creation” or “Attempt to create duplicate account”.

I was able to achieve this with the following Linq, but the query’s performance caused the webpage to timeout and blocked other queries to the table.

To optimize this, I wanted to use an entirely SQL solution. One way of doing so could be using multiple

but I need to filter on many different actions, not just the two in this example, causing too long of a query with multiple OR LIKE statements.

Finally, I would like to use something similar to

but the problem is the list contains substrings which will be found in the UserAction column. It would be great if I could use the entire UserAction string in the list used by the IN operator, but because some strings have variable data (like the email address), I need to match substrings.

So, what I am looking for is a way to achieve the hypothetical

where a list of substrings can be matched on the values of a column in SQL.

Thanks for your time.

The following SQL can be used to reproduce the situation.

Advertisement

Answer

I got it to work; it no longer times out and doesn’t block any other services.

I did this by building an SQL query and running it directly against the database.

The resulting SQL query is as follows

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement