简体   繁体   English

MS Access SQL查询结果

[英]MS Access SQL query results

I have two tables: 我有两个表:

rapprovals_tbl

rId rAssignment rState  rApprover   rapprovaldt rType   rNotes
    12345678                    
1   12345679    Paid    12345678    31/05/2015 18:23    Flex    
5   12345679    Approved    12345678    14/05/2015 18:23    Normal  
6   12345679    Pending         Normal  

timerecord_tbl

RowID   Assignment1 wMonth  StartTime   EndTime     
1   12345679    Mar-15  17/03/2015 11:29    18/03/2015 16:12    Flex    
5   12345679    Mar-15  17/03/2015 11:00    17/03/2015 12:00    Normal  
6   12345679    Mar-15  17/03/2015 11:50    18/03/2015 16:11    Normal  

I have form with two combo boxes, which are linked and worked on this source; 我有两个组合框的表单,这些组合框已链接并在此源上工作; Box 1 - 方框1-

Select [staffid] FROM [control_tbl] WHERE [supervisorid]  = '12345678'

Box 2 专栏2

SELECT timerecord_tbl.[RowID]
FROM timerecord_tbl
INNER JOIN rapprovals_tbl ON timerecord_tbl.RowID = rapprovals_tbl.rId
WHERE (((timerecord_tbl.[Assignment1])='" & Box 1 & "'
    AND (rapprovals_tbl.[rState] is null ) Or (rapprovals_tbl.[rState] = 'Pending' )));

I want to get only those RowID which are related to Box 1 employee record in Box 2. 我只想获取与框2中的框1员工记录相关的RowID。

How do I go about this, currently its listing all row ids. 我该如何处理,目前它列出了所有行ID。

I would appreciate any help. 我将不胜感激任何帮助。

Try changing your SQL for Box 2, like this: 尝试更改Box 2的SQL,如下所示:

SELECT timerecord_tbl.[RowID]
FROM timerecord_tbl
INNER JOIN rapprovals_tbl ON timerecord_tbl.RowID = rapprovals_tbl.rId
WHERE (timerecord_tbl.[Assignment1]='" & Box 1 & "')
   AND ((rapprovals_tbl.[rState] is null ) Or (rapprovals_tbl.[rState] = 'Pending' )));

I think @MarcB was saying the same thing. 我认为@MarcB在说同样的话。 Your "OR" statement was being applied to the entire WHERE clause instead of just the other rState filter. 您的“ OR”语句将应用于整个WHERE子句,而不仅仅是其他rState过滤器。 Changing the parentheses will separate it properly and fix it. 更改括号将正确分隔并修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM