Access 2003 中的条件标准

conditional criteria in access 2003

我是 Access 2003 的新手,我一直对所谓的内部联接遇到一些问题。我有两个无法编辑的 tables,所以我正在查询它们,两个 tables 之一的信息与用户的个人资料相关,第二个是与他们相关的辅助信息像电子邮件地址。

我的问题是我需要将标准应用于 table 2(辅助),但有时记录不存在,因为并非所有 table 1 都在 [=48] 中匹配=] 2. 所以我选择保留 table 1 中的所有字段并且只匹配 table 2,但是由于我对 table 2 的标准,我永远不会得到结果,除非table 中有值 2.

我在 table 1 中有一个字段让我知道 table 2 中是否会有值,所以我想做的是某种 if table1val = "1" Then table2val Like "*01*"。到目前为止这还没有奏效,可能是由于我的错误,所以我想知道这在设计视图中是否可行,因为从查找它似乎在 sql 视图中可能,但我'由于我缺乏 sql 知识,我没有成功尝试。

编辑:我所拥有的是有效的 table2 的标准:

在 note_txt 下:Like "*help*" Or Like "*HELP*" Or Like "*Help*"

在 category_code 下:"Emails" Or "Email"

在high_priority_ind下:Like "-1"

这些都有效,但如果字段显示#Deleted

,则return什么都不会

table1 中的字段我希望这些标准基于什么时候 prod_marker: Not Like "0"

我的理解是你不能在条件中有 if 因为如果你把“1”作为 table1 的条件,它就像 table1 = 1,你不能有table1 = 如果。那么有没有更好的方法来解决这个问题,因为我似乎不能

If(Not (prod_marker) Like "0") Then ((high_priority_ind) Like "-1")

下面是我想出的 SQL,它只是让我的访问崩溃(我没有包括 SELECT 和 FROM,因为它很长,我不确定它是否是必要):

WHERE (((dbo_client_link.link_id_txt)=[Enter Policy Number]) AND
 ((dbo_client_link.link_relationship_code)="O" Or 
(dbo_client_link.link_relationship_code)="J") AND 
((dbo_producer.aga_direct_ind)  Like "0") Or 
(((dbo_producer.aga_direct_ind) Like "-1" ) And 
( (dbo_note.note_txt) Like "*help*" Or 
(dbo_note.note_txt) Like "*HELP*") AND 
((dbo_note.category_code)="Emails" Or 
(dbo_note.category_code)="Email") AND 
((dbo_note.high_priority_ind) Like -1)))

My issue is that I need to apply criteria to table 2 (auxilary), but sometimes the record doesn't exist because not all of table 1 has a match in table 2.

您需要使用从 Table1(主)到 Table2(辅助)的左连接。如果您在设计视图中执行此操作,您应该能够右键单击连接(两个表之间的线),然后转到连接属性。您想要 select 包含 Table1 中的所有记录,并且仅包含 Table2 中连接字段相等的记录

现在您可以使用 Table1.prod_marker <> "0" 表达式作为条件(您不需要 LIKE 运算符,因为您没有使用通配符搜索)。按照这些思路:prod_marker 字段中有哪些类型的值?是只有“0”和“1”,还是有其他可能的值?如果你只会看到“0”或“1”,你也可以使用 Table1.prod_marker = 1

如果您还想根据 Table2 中的值过滤记录,您可以添加 OR 条件(如 high_priority_ind = "-1"UCASE(note_txt) like "*HELP*"UCASE(category_code) like "*EMAIL*"

像这样: