如何在一个表中检查多种类型的验证

时间:2014-04-10 15:00:09

标签: sql vb.net dataset database-table

所以我有一个场景。

未来必须设置这4项申请费,且没有结束日期或结束日期。

(FeeTypeID = 16 AND FeeRequirementTypeID = 18)
(FeeTypeID = 17 AND FeeRequirementTypeID = 18)
(FeeTypeID = 18 AND FeeRequirementTypeID = 18)
(FeeTypeID = 19 AND FeeRequirementTypeID = 18)

现在我如何将它放入if语句?

1 个答案:

答案 0 :(得分:0)

使用AND和OR:

select ...
from ...
where  
(
  (FeeTypeID = 16 AND FeeRequirementTypeID = 18) or
  (FeeTypeID = 17 AND FeeRequirementTypeID = 18) or
  (FeeTypeID = 18 AND FeeRequirementTypeID = 18) or
  (FeeTypeID = 19 AND FeeRequirementTypeID = 18) or
)
and
(
  end_date is null or
  end_date > now() -- or whatever expression your dbms uses for today
);

编辑:我只是注意到它总是在FeeRequirementTypeID = 18.所以简单地说:

select ...
from ...
where FeeRequirementTypeID = 18 
and FeeTypeID in (16,17,18,19)
and ( end_date is null or end_date > now() );