搜索包含字符串Access 07的字段

时间:2012-03-01 19:49:55

标签: sql ms-access

当天早些时候我发现了以下问题。

    SELECT DISTINCT Visits.KHA_ID, Visits.totalCharges
    FROM (Visits INNER JOIN (ICDTable INNER JOIN ICDVisitsJxn ON ICDTable.ICD9ID = ICDVisitsJxn.ICD_IDFK) ON Visits.ID = ICDVisitsJxn.VisitsIDFK) 
INNER JOIN (ICDTable AS ICDTable_1 
INNER JOIN ICDVisitsJxn AS ICDVisitsJxn_1 ON ICDTable_1.ICD9ID = ICDVisitsJxn_1.ICD_IDFK) ON Visits.ID = ICDVisitsJxn_1.VisitsIDFK
    WHERE (((ICDTable.Description) 
Like "*[enter term]*") AND ((ICDTable_1.Description) Like "*[enter another term]*"));

这是我想要的方式。但是,我更愿意,而不是必须在相应的字段中键入用户可以搜索文本字符串的确切文本。这类似于这里的* * *构造Access使用。我总是硬编码子串。任何人都知道如何以编程方式执行此操作。

2 个答案:

答案 0 :(得分:3)

如果您在Access中运行此功能,只需添加*:

即可
WHERE (((ICDTable.Description) Like "*" & [enter term]  & "*") 
AND ((ICDTable_1.Description) Like "*" & [enter another term] & "*"));

您可以参考表单上的控件:

WHERE (((ICDTable.Description) Like "*" & Forms!MyForm!FirstTerm  & "*") 
AND ((ICDTable_1.Description) Like "*" & Forms!MyForm!SecondTerm & "*"));

答案 1 :(得分:2)