如何仅在参数具有特定值时才激活访问查询条件 OR 语句?

How to make an access query criteria OR statement active only when a parameter has certain values?

我有这个查询:

SELECT t_Data.ID, t_Data.Location, t_Data.[VG's], t_Data.BinSize, t_Data.Date, t_Data.Time, t_Data.RPM001, t_Data.POW001, t_Data.WSP001, t_Data.YAW001, t_Data.RPM002, t_Data.POW002, t_Data.WSP002, t_Data.YAW002
FROM t_Data
WHERE (((t_Data.Location)=[Forms]![f_Main]![LocationCombo]) AND ((t_Data.BinSize)=[Forms]![f_Main]![BinSizeCombo]) AND ((t_Data.POW001)>[Forms]![f_Main]![LowerLimit] And (t_Data.POW001)<[Forms]![f_Main]![UpperLimit]) AND ((t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW001)>=Sector1_dsp() And (t_Data.YAW001)<=Sector2_dsp()) AND ((t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text] And (t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text]) AND ((t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW002)>=Sector1_dsp() And (t_Data.YAW002)<=Sector2_dsp())) OR (((t_Data.Location)=[Forms]![f_Main]![LocationCombo]) AND ((t_Data.BinSize)=[Forms]![f_Main]![BinSizeCombo]) AND ((t_Data.POW001)>[Forms]![f_Main]![LowerLimit] And (t_Data.POW001)<[Forms]![f_Main]![UpperLimit]) AND ((t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP001)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP001)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW001)>=Sector3_dsp() And (t_Data.YAW001)<=Sector4_dsp()) AND ((t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text] And (t_Data.POW002)>[Forms]![f_Main]![LowerLimit_Text] And (t_Data.POW002)<[Forms]![f_Main]![UpperLimit_Text]) AND ((t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text] And (t_Data.WSP002)>[Forms]![f_Main]![LowerLimitMs_Text] And (t_Data.WSP002)<[Forms]![f_Main]![UpperLimitMs_Text]) AND ((t_Data.YAW002)>=Sector3_dsp() And (t_Data.YAW002)<=Sector4_dsp()));

名为 YAW001YAW002 的字段是风力涡轮机的方向。

我有一个带有功能的表格,可以只选择北风,北为 0 度。东经90度。

问题是只要角度为 0->360 度,我的限制就可以正常工作。当我选择从北方看 90 度 windows 时,我需要介于 360-90/2 和 360+90/2 之间的值。然后我得到一个标准:

Yaw001 > 315 AND Yaw001 < 405

但是由于所需的值是 315 到 45 度,我遇到了问题。 我需要它来查看如果限制高于 360,则标准应为

Yaw001 > 315 OR Yaw001 < 45

如何破解这个?

同样适用于Yaw002

系统也可以逆时针旋转,因此所需的值为

Yaw001 < -45 AND Yaw001 < 45

同样,最低值为 0,因此需要

Yaw001 > 315 OR Yaw001 < 45

我试过在 OR:

中使用这个语句
IIf(Sector4_dsp()>360;<=Sector4_dsp()-360;<0)

但即使它是真的,它也不return 标准<=Sector4_dsp()-360

希望大家关注我。

此致,埃米尔。

我手边没有 MSAccess,但 modulo 操作肯定能满足您的需求?在您的 SQL 查询中使用(角度 MOD 360)。例如,(-45MOD360)=315,(405MOD360)=45.

编辑,添加示例条件表达式

假设北边各成 90 度弧;

direction = 0
min = (direction - 90/2 mod 360)
max = (direction + 90/2 mod 360)
Yaw001 = Yaw001 mod 360

然后

(min <= max and Yaw001 >= min and Yaw001 =< max) or (min > max and (Yaw001 > min or Yaw001 < max)