Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL LIKE Operator return nothing 2

Status
Not open for further replies.

tofuTnT

Technical User
Jul 17, 2003
67
US
I am working on an intranet application and use Access as the database.
There is a query that I have
Code:
<CFQUERY DATASOURCE="#DSN#" NAME="GET_SEARCH_RESULT">
	SELECT * FROM WL_TREES
	WHERE TREENAME LIKE '3*'
</CFQUERY>
It returns nothing in ColdFusion, if I copy just the SQL and run it in Access, it returns with the expected result.

Any idea why ColdFusion query didn't work?

Thanks,
tofuTnT
 
Try using % or _ as wildcards and see what happens.

Cheers,

Bluetone
 
From Access help:
Using Wildcard Characters in String Comparisons
Built-in pattern matching provides a versatile tool for making string comparisons. The following table shows the wildcard characters you can use with the Like operator and the number of digits or strings they match.

Character(s) in pattern Matches in expression
? or _ (underscore) Any single character
* or % Zero or more characters
# Any single digit (0— 9)
[charlist] Any single character in charlist
[!charlist] Any single character not in charlist


You can use a group of one or more characters (charlist) enclosed in brackets ([ ]) to match any single character in expression, and charlist can include almost any characters in the ANSI character set, including digits. You can use the special characters opening bracket ([ ), question mark (?), number sign (#), and asterisk (*) to match themselves directly only if enclosed in brackets. You cannot use the closing bracket ( ]) within a group to match itself, but you can use it outside a group as an individual character.

In addition to a simple list of characters enclosed in brackets, charlist can specify a range of characters by using a hyphen (-) to separate the upper and lower bounds of the range. For example, using [A-Z] in pattern results in a match if the corresponding character position in expression contains any of the uppercase letters in the range A through Z. You can include multiple ranges within the brackets without delimiting the ranges. For example, [a-zA-Z0-9] matches any alphanumeric character.

It is important to note that the ANSI SQL wildcards (%) and (_) are only available with Microsoft® Jet version 4.X and the Microsoft OLE DB Provider for Jet. They will be treated as literals if used through Microsoft Access or DAO.
(emphasis mine)

Other important rules for pattern matching include the following:

An exclamation mark (!) at the beginning of charlist means that a match is made if any character except those in charlist are found in expression. When used outside brackets, the exclamation mark matches itself.
You can use the hyphen (-) either at the beginning (after an exclamation mark if one is used) or at the end of charlist to match itself. In any other location, the hyphen identifies a range of ANSI characters.
When you specify a range of characters, the characters must appear in ascending sort order (A-Z or 0-100). [A-Z] is a valid pattern, but [Z-A] is not.
The character sequence [ ] is ignored; it is considered to be a zero-length string (“”).



Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Bluetone/philhege,

Thank you both for the advise, I used % instead of * and it seems to worked as expected through ColdFusion.

Use * instead of % in Access gave expected result as well.

hmm....should I say Access sucks ? :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top