在ACCESS中LIKE的用法
Access里like的通配符用法是这样:
“?”表示任何单一字符; “*”表示零个或多个字符; “#”表示任何一个数字
所以应该是:
select * from databasename where fieldname like '*XX*'
原来在SQL SERVER 里是用%%的,在ACCESS里是用**号的,怪不得都找不到数据!
但如果在VS2005的TableAdapter里又要用%%,用* 不行!!!
所以应该是:
select * from tablename where fieldname like '*XX*'
原来在SQL SERVER 里是用%%的,在ACCESS里是用**号的,怪不得都找不到数据!
但如果在VS2005的TableAdapter里又要用%%,用*不行!
ACCESS中LIKE的用法
Like Operator
Compares a string expression to a pattern in an SQL expression.
Syntax
expression Like 'pattern'
The Like operator syntax has these parts:
Part Description
expression SQL expression used in a WHERE clause.
pattern String or character string literal against which expression is compared.
Remarks
You can use the Like operator to find values in a field that match the pattern you specify. For pattern, you can specify the complete value (for example, Like “Smith”), or you can use wildcard characters to find a range of values (for example, Like “Sm*”).
In an expression, you can use the Like operator to compare a field value to a string expression. For example, if you enter Like “C*” in an SQL query, the query returns all field values beginning with the letter C. In a parameter query, you can prompt the user for a pattern to search for.
The following example returns data that begins with the letter P followed by any letter between A and F and three digits:
Like 'P[A-F]###'
The following table shows how you can use Like to test expressions for different patterns.
Kind of match
Pattern Match
(returns True) No match
(returns False)
Multiple characters a*a aa, aBa, aBBBa aBC
*ab* abc, AABB, Xab aZb, bac
Special character a[*]a a*a aaa
Multiple characters ab* abcdefg, abc cab, aab
Single character a?a aaa, a3a, aBa aBBBa
Single digit a#a a0a, a1a, a2a aaa, a10a
Range of characters [a-z] f, p, j 2, &
Outside a range [!a-z] 9, &, % b, a
Not a digit [!0-9] A, a, &, ~ 0, 1, 9
Combined a[!b-m]# An9, az0, a99 abc, aj0
【相关文章:】
ACCESS的参数化查询
SQL语句集锦
SQL中like语句详解
ACCESS和MSSQL里如何随机取出数据库的纪录
配置,链接access数据库
在ASP中使用SQL语句之3:LIKE、NOT LIKE和 BETWEEN
如何在.NET框架下创建Access数据库和表?
ASP.NET 2.0中随机读取Access数据库记录
【发表评论】【打印此文】【关闭窗口】【点击数: 】
