访问SQL子查询

时间:2014-07-18 10:06:46

标签: sql

我有以下子查询,如果订单详细信息状态中的所有项目= 2,则更新订单标题,但是我也有一些StatusFK = 4(已删除)的记录如何将其添加到我的子查询中以便它忽略任何StatusFK的4?

  UPDATE tblOrder
  SET tblOrder.Statusfk = 2
   WHERE NOT EXISTS (SELECT 1
              FROM tblOrderDetail
              WHERE tblOrderDetail.OrderFK = tblOrder.OrderPK AND
                    tblOrderDetail.StatusFK <> 2 AND
                    tblOrder.StatusFK);

1 个答案:

答案 0 :(得分:0)

谢谢你们的Anwsers!最后这很简单。

UPDATE tblOrder SET tblOrder.Statusfk = 2
WHERE (((Exists (SELECT 1
              FROM tblOrderDetail
              WHERE tblOrderDetail.OrderFK = tblOrder.OrderPK AND
                    tblOrderDetail.StatusFK <> 2 AND
                    tblOrder.StatusFK AND tblOrderDetail.StatusFK <> 4
             ))=False));