【问题标题】:SQL Correct Syntax for Selecting between 3 category in the field用于在字段中选择 3 个类别的 SQL 正确语法
【发布时间】:2012-10-04 00:04:52
【问题描述】:

我只想知道如何在MS access中创建SQL语法。

我要做的是从表中选择名称为Employee 的表,其中字段名(位置)等于ManagerSupervisorActing Supervisor,字段名( status) 等于active

我在下面找到的代码不起作用:

SQL = "SELECT * FROM `Employee` WHERE `position`= '" + "Manager" + "' OR `position`= '" + "Supervisor" + "' OR `position`= '" + "Acting Supervisor WHERE `status`= '" +"ACTIVE"'";

谢谢。

【问题讨论】:

    标签: c# sql wpf ms-access


    【解决方案1】:

    您实际上并不需要所有字符串连接,Acting Supervsior 之后缺少引号,并且您不能两次使用 WHERE 关键字 - 改用 AND

    SQL = "SELECT * FROM `Employee` WHERE (`position` = 'Manager' OR `position` = 'Supervisor' OR `position` = 'Acting Supervisor') AND `status` = 'ACTIVE'";
    

    更新

    您还可以通过使用IN 关键字来稍微简化逻辑:

    SQL = "SELECT * FROM `Employee` WHERE `position` IN ('Manager', 'Supervisor', 'Acting Supervisor') AND `status` = 'ACTIVE'";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-07
      • 2016-12-09
      • 1970-01-01
      相关资源
      最近更新 更多