i am doing conditional formatting on a report in access
i need to check if a certain string exists in a field as the condition in conditional formatting. something like this:
[field_name] like '%something%'
will this kind of condition work?
You have to use asterisk with MS Access.
[field_name] like '*something*'
For a single character, you can do this
[field_name] like 'fieldnam?'
For three characters, you can do this
[field_name] like 'fieldna???'
Access uses the asterisk instead of the percent. Try
[field_name] like "*something*"
Yes, but it is a condition...
so you need something like
SELECT * FROM Foobar WHERE
[field_name] LIKE '*something*'
Related
What I want to do is I want to filter from a table where it specifically starts with something but when I try to filter out 'BRA_' it should only give me fields that has BRA_ on it and not BRAzil BRAma which is what the Like % operator is giving me. I also tried using Like _ but that only took the underscore out completely. Is there a way to do this?
SELECT *
FROM MyTable
WHERE MyColumn Collate Latin1_General_CS_AS LIKE 'BRA?_' ESCAPE '?'
In the LIKE operator, ESCAPE create your own escape char that must be placed before the joker character that you would find as a litteral in the string.
How can I make Access treat *1* as a string instead of using wildcard in the SQL
SELECT * FROM TABLE1 WHERE ID IN ("*1*","*2*");?
Sadly, this is a limitation of Access. You can use [*] to search for any single character, so:
TABLE1 WHERE ID IN ("[*]1[*]","[*]2[*]")
Would match any single leading and trailing character with 1 or 2 in the middle. Not what you want, but closer.
In this expression:
WHERE ID IN ("*1*", "*2*")
MS Access does treat the values as strings and not wildcards. The wildcards are only used for LIKE.
If you want them to be treated as wildcards, you need to use LIKE. That would require OR:
WHERE ID LIKE "*1*" OR ID LIKE "*2*"
Or more simply as:
WHERE ID LIKE "*[1-2]*"
I have a query like this:
select name,label from tablename where label like '*[form]![label search]![searchtxt]*';
I know the query works in the sense that if I replace the "[form]![label search}![searchtxt]" with an actual word, the query works. When I run the query as is, the data from the form doesn't go into the query so I get no rows.
How can I get the like part of the query to work with an input from a form. I realize that this will probably require some VBA in addition to SQL.
Thanks
You need to concatenate the asterisks in. Something like:
select name,label from tablename where label like '*' & [form]![label search]![searchtxt] & '*';
To extract only the appropriate rows, i have to do something like Mycolum in ('x%','f%') : wich means i want all the rows where Mycolumn is starting with x or f,
i can use REGEXP_LIKE(Mycolumn, '^x', 'i') : to extract all rows where Mycolumn start with x how can i add OR in regex to tell to my function i need also rows starting with f
thanks
You can do this:
REGEXP_LIKE(Mycolumn, '^[xf]')
You can use OR to provide both the conditions.
SELECT * FROM TABLE_NAME
WHERE REGEXP_LIKE(COLUMN, '^x')
OR REGEXP_LIKE(COLUMN, '^f');
I love regexes, but you don't need them for this. I would use just normal LIKE, which may be faster:
WHERE MyColumn LIKE '[^xfXF]%'
LIKE also has a more readable syntax, in my opinion at least.
I'm trying to construct an SQL query that looks for multiple different things I think the like command is the best way to achieve this
the line in the query is:
where *field* like 'AB%' it lists all the instaces in the table where it begins AB....
when i try and add multiple instances though i get an error message, I want to do something like the following:
where *field* like ('AB%','CD%','EF%')
So I get the fields for specific entries that start with the list of text I have provided
Could somebody help me with this please?
You want OR
WHERE field LIKE 'AB%'
OR field LIKE 'CD%'
OR field LIKE 'EF%'
If you are using other WHERE clause criteria, you'll need to bracket off the OR clauses using parenthesis.
Hope it helps...
EDIT:
After your comment, you could try using regular expressions, especially REGEXP_LIKE in your WHERE clause.
Something along the lines of (untested):
SELECT *
FROM table
WHERE regexp_like(field, '^(AB|CD|EF).*$')
WHERE *field* LIKE 'AB%' OR *field* LIKE 'CD%' OR *field* LIKE 'EF%'
If you are using Oracle, you can write:
where regexp_like(t1, '^AB|^CD|^EF')
etc.
You could use the instr function. If it finds the substring you want at the first position of the string, it would return 1:
where instr(field,'AB') = 1
OR instr(field,'CD') = 1
OR instr(field,'ED') = 1
If you want to do it with single string, try to use REGEXP:
WHERE *field* REGEXP 'AB(.*)|CD(.*)|EF(.*)'