来自VB的SQL查询

时间:2016-12-27 11:41:17

标签: mysql vb.net

当我使用下面的代码时,我得到了所需的输出:

mQuery = "Select FileName, Filetype from CredoReports where "
mQuery = mQuery & " FileName = '" & mSearchTag & "'"
mQuery = mQuery & " or FileName like '" & mSearchTag & "%'"
mQuery = mQuery & " order by FileName ASC"

SQL DB Trace收到的查询是

SELECT "FileName" ,"FileType"  FROM "dbo"."CredoReports" WHERE ((("FileName" = 'L-R5' )  OR ("FileName" LIKE 'L-R5%' ) ) ORDER BY "dbo"."CredoReports"."FileName" 

当我使用下面的代码时,我没有得到任何输出。

mQuery = "Select FileName, Filetype from CredoReports where "
mQuery = mQuery & " FileName = '" & mSearchTag & "'"
mQuery = mQuery & " or FileName like '" & mSearchTag & "[^0-9]%'"
mQuery = mQuery & " order by FileName ASC"

SQL Trace收到的查询是

SELECT "FileName" ,"FileType"  FROM "dbo"."CredoReports"

当我使用[^0-9]时,SQL DB跟踪中缺少WHERE子句。

额外信息:Set oRecordSet = CurrentDb.OpenRecordset(mQuery)

1 个答案:

答案 0 :(得分:1)

您使用的数据库是什么?唯一一个将[^0-9]视为含义的数据库"没有数字" for like是SQL Server(和Sybase)。

在MySQL中,您将使用regexp

mQuery = mQuery & " or FileName regexp '^" & mSearchTag & "[^0-9].*$'"