Debugging Access SQL - sql

I have this query in access but it doesn't return any result when I use the Like function. It does return result when I set it to equal to.
Select * from myTable where name like "*Al#pp*"
note that the # sign is part of the spelling to lookup and not a wildcard, but I think access is taking it as a wildcard.

Since # is not supposed to be a wildcard then you have to escape it. Try:
Select * from myTable where name like "*Al[#]pp*"

Related

How to use LIKE in WHERE clause to get first 5 characters of variable?

I have a variable varchar that always takes in 10 digits. How can I use the LIKE operator to find/use only the first 5 digits of the variable?
my query:
variable IN VARCHAR2
SELECT * FROM items WHERE name LIKE SUBSTRING(variable, 1, 5)
... WHERE name LIKE '12345%'
will match any string that starts 12345. the '%' is a wildcard. You can also use the wildcard to match anywhere in the string: ... WHERE name LIKE '%12345%' will match a string with 12345 anywhere within it.
Edit for completeness: WHERE name LIKE '%12345' will match any string that ends with those five characters.
Try this:
SELECT * FROM items WHERE name LIKE (SUBSTRING(variable, 1, 5) + '%')
I guess you can use LEFT() like this:
SELECT * FROM items WHERE LEFT(name,5)=LEFT(variable,5);
Or if you you want to use LIKE with a wildcard, you can do this:
SELECT * FROM items WHERE name LIKE CONCAT(LEFT(variable,5),'%')
A few more example in the Demo fiddle
Edit: The above solution is for MySQL/MariaDB because earlier the tag of this question have MySQL but it's also my fault for not recognizing OP description of the datatype VARCHAR2. I might as well just post a suggestion related to the rdbms.
So, my first suggestion there using LEFT() however Oracle don't have that function, therefore:
SELECT * FROM items WHERE SUBSTR(name,1,5)=SUBSTR(variable,1,5);
or using concatenation operator
SELECT * FROM items WHERE name LIKE SUBSTR(variable,1,5)||'%'
Demo fiddle

ACCESS SQL IN function with wildcard

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]*"

SQL Wildcard in Access: "%" and "_" don't works

I tryed some wildcards in Access in Where statement, but they don't works. For example:
This query SELECT staff.* FROM staff;returns:
I tryed to do a query with wildcard SELECT staff.* FROM staff WHERE (staff.s_name LIKE "A%");
but it returns an empty table:
What is the reason? My wildcard doesn't work
(s_name is the second column)
(look that "firstname" is the tag of "s_name" only for the view)
Wildcard character in Access is *, not % unlike in SQL Server.
See MSDN for details.
No, no, no, use '*', not '%'. Or, use 'Like'.
http://www.techrepublic.com/article/10-tips-for-using-wildcard-characters-in-microsoft-access-criteria-expressions/
https://www.techonthenet.com/access/queries/like.php
https://www.techonthenet.com/access/queries/like2007.php
For instance:
Like 'm*'
Result: all values that start with m
Like 'm'
Result: all values that contain m
Like '*m'
Result: all values that end with m

Trying to use Wildcards in SQLite Browser but its not working

i want to display all the names that start with S.
so i tried writing this:
select
*
from
User
where
name = 'S%';
0 rows returned.
select
*
from
User
where
name like 'S%';
If you want to read up on how wildcards work: http://www.w3schools.com/sql/sql_wildcards.asp

MS Access: searching a column for a star/asterisk

I'm looking for a way to search a column of string datatype which contains a * - the problem is that the star or asterisk is a reserved symbol. The following query doesn't work properly:
select * from users where instr(pattern,"*")
How can you write an Access query to search a column for an asterisk?
You can search for reseverd charaters in Access by using square brackets:
select * from users where pattern like "*[*]*"
yay, found it out by myself:
select * from users where instr(pattern,chr(42))
Just use
select * from users where instr(pattern,"*") > 0
From Access: Instr Function
In Access, the Instr function returns
the position of the first occurrence
of a string in another string.
Use the ALIKE function because its wildcard characters do not include * e.g.
SELECT * FROM Users WHERE pattern ALIKE '%*%';
(Edit by DWF: see #onedayone's useful explanation of ALIKE)