Wildcards in the database

Anyone have any pointers, how can I store wildcards in the database and see which lines (lines) match the line? It can be done?

eg. DB contains a table like:

two column table with wildcards in col one

Thus, john3136 should receive a 10-fold salary. fred3136 would receive half its regular payment. harry3136, possibly the application crashes because there is no relevant data; -)

The code should do something like:

foreach(Employee e in all_employees) { SELECT Multiplier FROM PayScales WHERE //??? e.Name matches the PayScales.Name wildcard } 

Thanks!

Edit This is a real world problem: I have a parameter file containing wildcards. The code is currently iterating through employees, iterating through a param file looking for a match - you can understand why I would like to "databaserize" it; -)

Wildcards are optional. The line could say "john3136" for only one employee. (The real application is not really an employee, so it makes sense even if it looks redundant in this simple example)

One option is open: I know all the names of the employees before I start, so that I can iterate through them and effectively expand the wildcards in the temporary table. (therefore, if I have john3136 * in the start table, it can expand to john3136, john31366, etc. based on the list of employees). I was hoping to find a better way than this because it requires more maintenance (for example, if we add functionality to add an employee, we need to maintain an extended wildcard table).

0
sql regex
source share
1 answer
 SELECT * FROM payscales WHERE e.Name LIKE regexp_replace(name, E'^\\*|\\*$', '%', 'g'); 

I do not know which database you are using. The above query works on postgresql and will simply replace your trailing and leading wildcard with % , which is wildcard LIKE .

If there is no template, it must match the full line.

0
source share

All Articles