MS Access SQL: in a query check if a field contains spaces and if it's equal to another field without them

StackOverflow https://stackoverflow.com/questions/22098167

Question

Is it possible to check if a table field contains spaces (one or multiple spaces) by using an MS-Access query? (if yes, how?)

I would to know if the A1 field of Table1 contains spaces and check if it without spaces is equal to field B1 of Table2 (without changing the tables data).

I've MS-Access 2007.

EDIT

Correct answer for MS-Access 2007:

SELECT DISTINCT your_table1.id FROM your_table1, your_table2 
WHERE A1 LIKE '* *' 
AND REPLACE(A1,' ','') IN (SELECT B1 FROM your_table2)
Was it helpful?

Solution

You can use Replace in where clause to check spaceless version of A1

SELECT * FROM your_table 
WHERE A1 LIKE '% %' 
AND REPLACE(A1,' ','') IN (SELECT B1 FROM Table 2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top