【问题标题】:Access - Different queries based on blank valuesAccess - 基于空白值的不同查询
【发布时间】:2014-06-17 21:31:29
【问题描述】:

我有一个 MS Access 数据库运行一个查询,该查询从“TableX”中获取所有员工,这些员工在“TableY”中具有相同的 Employee_Key。

问题是:Employee_Key 列中的一些值是空白的。发生这种情况时,我应该按 Employee_Email 过滤,就像我使用 Employee_Key 一样。

那么,我如何验证 Employee_Key 是否为空白,当它实际上为空白时,如何使用不同的过滤器(电子邮件)运行另一个查询?

Ps:一旦这项任务来自我的工作,我现在没有确切的查询。

【问题讨论】:

  • 您好,欢迎来到 Stack Overflow。如果您没有确切的查询也没关系 - 但这个描述真的很难理解。如果您能给我们您目前所拥有的(甚至是伪代码),这将使我们更容易为您提供帮助。

标签: sql ms-access


【解决方案1】:
select x.*
from tableX x
join tableY y on 
              (
                 '' not in (x.Employee_Key, y.Employee_Key)
                 and x.Employee_Key = y.Employee_Key 
              )
              or 
              (
                 '' in (x.Employee_Key, y.Employee_Key) 
                 and x.Employee_Email = y.Employee_Email
              )

【讨论】:

  • 于尔根,非常感谢您的回复。它看起来比我想象的要简单。我会试试这个然后我告诉你:)
【解决方案2】:

如果我理解正确的逻辑:

select x.*, y.*
from tableX as x inner join
     tabley as y
     on x.employee_key = y.employee_key or
        (x.employee_key is null and x.employee_email = y.employee_email);

【讨论】:

  • 戈登,您的方法似乎也很有帮助。它肯定会帮助我。非常感谢。
猜你喜欢
  • 2018-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
  • 1970-01-01
相关资源
最近更新 更多