MS Access query with pattern - ms-access

I am trying to implement in MS Access following query filter. I am trying do not show the numbers from my table which contains following pattern:
"NNNNNN_NNNN_NNN" AND "NNNNNN_NNNN_NNN-S/Z"
If I have in my database a number "123456_123_123" or "12345_1234_12" I cannot see them. So my filter pattern doesn't work correctly. Is there possibility to work in Access Query with underline symbols? How can I create correct pattern?
Thank you for any tip!

Use the operator LIKE:
SELECT *
FROM tablename
WHERE ([columnname] NOT LIKE '######_####_###')
AND ([columnname] NOT LIKE '######_####_###-S/Z')
The wildcard '#' represents a single digit.

Related

MYSQL Find entries that contain more than 7 numbers

I need to find entries that contain more than 7 numbers in one of my mysql tables BUT the numbers are separated by letters or anything else.
What I have is this little piece of code I use to find entries like dsc123456789:
select * from crawl where title regexp '[0-9]{7}'
How can I find entries like dsc-123-456_78B9? I tried different things but without success so far.
Thanks
You can use the following solution:
SELECT *
FROM crawl
WHERE title REGEXP '(([^[:digit:]])?[[:digit:]]){8,}';
Why the original query of the answer doesn't work?
-- this query doesn't work!
SELECT *
FROM crawl
WHERE title REGEXP '\d([^\d]?\d){7,}'
MySQL can't use character groups like \d (digits). So the query fails every time. On PHP and other languages the regular expression would look like this:
\d([^\d]?\d){7,}
but on MySQL this isn't valid. So you have to use the character classes of MySQL to solve this:
(([^[:digit:]])?[[:digit:]]){8,}
Hint: Make sure you use {8} or {8,} instead of {7} since you want to find all entries with more than 7 numbers / digits.

Regex not supported in sql command with "contains" clause

I am not a seasonal Windows user, I got a task wherein I had to query the Window Index search table i.e "Systemindex" for fetching some user specific data from the db.
And for this I have to match a pattern basically a regular expression while fetching the data.
SELECT System.FileName, System.ItemPathDisplay, System.DateCreated, System.DateModified, System.ItemName, System.KindText FROM Systemindex WHERE Contains('“(?=^[A-Za-z\d!##\$%\^&\*\(\)_\+=]{9,32}$)”');
The above would allow us to search for say stored passwords.
But when I query the db using the below command I was getting an error. And later I came to know that the "contains" clause
does not support regular expression. Is there an alternative to achieve this?
there is REGEXP operator http://dev.mysql.com/doc/refman/5.7/en/regexp.html,
use smth like this
SELECT * FROM Systemindex WHERE some_column REGEXP 'your_regex'

Does a RegEx Pattern need to be modified to be used with SQL in MySql?

I'am trying to write a SELECT-Statement to retrieve a list of Usernames from my Database. My Pattern is: /placeholder\d+/ig and I already tested it and can confirm it is working properly. I'am trying to retrieve every Placeholder in the Table.
I also tried to escape the \ after placeholder.
My SQL-Statement is: SELECT * FROM table WHERE (name REGEX '/placeholder\d+/ig') ... I tried different variations with backticks, etc or LIKE instead of REGEXbut LIKEonly has % and _ as a Wildcard.
Does my RegEx pattern needs to be modified in order to work with MySQL?
Unlike most scripting languages, MySQL is not using the PREG library for regular expression matching.
So yes, you need to modify your regex to make it work properly in MySQL:
SELECT * FROM table WHERE name REGEXP 'placeholder[0-9]+'
OR
SELECT * FROM table WHERE name REGEXP 'placeholder[[:digit:]]+'
There are no short-hand character classes like \d in MySQL. Also, you do not use the regex-delimeter ("/../si" is just ".." in MySQL)
Read the documentation on regular expressions in MySQL for more information.

Mysql searching records containing wildcards

I have a table with tens of thousands of VIN numbers. Many of them look along the lines of this:
6MMTL#A423T######
WVWZZZ3BZ1?######
MPATFS27H??######
SCA2D680?7UH#####
SAJAC871?68H06###
The # represents a digit and the ? a letter (A-Z).
I want to search for the following: 6MMTL8A423T000000.
I am struggling to work out the logic. Should I use a function? Should I use mysql regex?
A regular expression match would be a good way to approach this problem. What you need to do is convert the vin expressions into valid regular expressions that represent the logic you've indicated. Here's a simple way to do that:
replace(replace(vin,'#','[0-9]'),'?','[A-Z]')
This would convert 6MMTL#A423T###### into 6MMTL[0-9]A423T[0-9][0-9][0-9][0-9][0-9][0-9]. Now using this converted format, do a regular expression match query:
select vin
from vins
where '6MMTL8A423T000000' regexp replace(replace(vin,'#','[0-9]'),'?','[A-Z]')
Sample Output: 6MMTL#A423T######
Demo: http://www.sqlfiddle.com/#!2/ee4de/4

Access query fields to be equal

I am teaching a guy to polish matura and they have to use Access sometimes.
I have a table with columns pyt_1, pyt_5. I would like to display only these rows in which these columns are equal.
In SQL it looks like that:
SELECT pyt_1, pyt_5
FROM Ankiety
WHERE pyt_1=pyt_5;
but he has to know how to do it in query design
I chose the pyt_1, pyt_5 column and added criteria pyt_1 = pyt_5 but ACCESS automatically converts it into string, how to avoid that?
He converted my SQL into query design but it's weird.
Your problem is that you write = pyt_5 into the criteria field for the column pyt_1, and Access automatically converts it into = "pyt_5", correct?
If yes, you need to put pyt_5 in braces ([ ]).
This makes the Access query editor recognize it as a column name.
Here is a screenshot (German Access version with German labels, but you get the idea):