Forum Discussion
JasonCanady
Jul 27, 2026Tin Contributor
Access Query Problem
Good afternoon. I have been trying to track down a very strange error that my database has thrown for the first time ever... the query performs a complex math equation based on temperature, chlorine ...
- Jul 28, 2026
You are comparing strings, not numeric values, and all your field values seem to be text, thus should be converted. Try this:
SELECT CT_ALL.CTDate, CT_ALL.[12AM], CT_ALL.[4AM], CT_ALL.[8AM], CT_ALL.NOON, CT_ALL.[4PM], CT_ALL.[8PM], CT_ALL.High, CT_ALL.CT1_Time, CT_ALL.Peak, CT_ALL.CT2_Time, CT_ALL.C, CT_ALL.T, Val(Format(CDbl(Nz([C], 1)) * CDbl([T]), '#.0')) AS CxT, CT_ALL.Sed_Cl2, CT_ALL.Sed_T, CT_ALL.Temp, CT_ALL.pH, CT_ALL.[3 Log], CT_ALL.Log, Val(Format(CDbl(Nz([C2], 0)) * CDbl([T2]), '#.0')) AS CxT2, CT_ALL.Sed_Cl2 AS C2, CT_ALL.Sed_T AS T2, IIf( [Temp_1] = '--', Null, IIf( Val([temp]) < 12.5, (0.353 * 0.5) * (12.006 + 2.71828183 ^ (2.46 - 0.073 * Val([Temp]) + 0.125 * Val([C]) + 0.389 * Val([pH]))), (0.361 * 0.5) * (-2.261 + 2.71828183 ^ (2.69 - 0.065 * Val([Temp]) + 0.111 * Val([C]) + 0.361 * Val([pH]))) ) ) AS CT_Required, Nz([Temp], '') AS Temp_1, CT_ALL.C AS C1, IIf([CxT] > [Ct_Required], 'YES', 'NO') AS ClearwellMet, IIf([CxT_Sum] > [CT_Required], 'YES', 'NO') AS Met_Overall, IIf( [temp_1] = '--', Null, IIf( Val([temp]) < 12.5, (0.353 * 3) * (12.006 + 2.71828183 ^ (2.46 - 0.073 * Val([Temp]) + 0.125 * Val([C]) + 0.389 * Val([pH]))), (0.361 * 3) * (-2.261 + 2.71828183 ^ (2.69 - 0.065 * Val([Temp]) + 0.111 * Val([C]) + 0.361 * Val([pH]))) ) ) AS 3Log FROM CT_ALL WHERE CT_ALL.CTDate Between [forms].[FiltrationPlant].[StartDate] And DateAdd('m', 1, ([Forms].[FiltrationPlant].[StartDate])) - 1;
GustavBrock
Jul 28, 2026MVP
You are comparing strings, not numeric values, and all your field values seem to be text, thus should be converted. Try this:
SELECT
CT_ALL.CTDate,
CT_ALL.[12AM],
CT_ALL.[4AM],
CT_ALL.[8AM],
CT_ALL.NOON,
CT_ALL.[4PM],
CT_ALL.[8PM],
CT_ALL.High,
CT_ALL.CT1_Time,
CT_ALL.Peak,
CT_ALL.CT2_Time,
CT_ALL.C,
CT_ALL.T,
Val(Format(CDbl(Nz([C], 1)) * CDbl([T]), '#.0')) AS CxT,
CT_ALL.Sed_Cl2,
CT_ALL.Sed_T,
CT_ALL.Temp,
CT_ALL.pH,
CT_ALL.[3 Log],
CT_ALL.Log,
Val(Format(CDbl(Nz([C2], 0)) * CDbl([T2]), '#.0')) AS CxT2,
CT_ALL.Sed_Cl2 AS C2,
CT_ALL.Sed_T AS T2,
IIf(
[Temp_1] = '--',
Null,
IIf(
Val([temp]) < 12.5,
(0.353 * 0.5) * (12.006 + 2.71828183 ^ (2.46 - 0.073 * Val([Temp]) + 0.125 * Val([C]) + 0.389 * Val([pH]))),
(0.361 * 0.5) * (-2.261 + 2.71828183 ^ (2.69 - 0.065 * Val([Temp]) + 0.111 * Val([C]) + 0.361 * Val([pH])))
)
) AS CT_Required,
Nz([Temp], '') AS Temp_1,
CT_ALL.C AS C1,
IIf([CxT] > [Ct_Required], 'YES', 'NO') AS ClearwellMet,
IIf([CxT_Sum] > [CT_Required], 'YES', 'NO') AS Met_Overall,
IIf(
[temp_1] = '--',
Null,
IIf(
Val([temp]) < 12.5,
(0.353 * 3) * (12.006 + 2.71828183 ^ (2.46 - 0.073 * Val([Temp]) + 0.125 * Val([C]) + 0.389 * Val([pH]))),
(0.361 * 3) * (-2.261 + 2.71828183 ^ (2.69 - 0.065 * Val([Temp]) + 0.111 * Val([C]) + 0.361 * Val([pH])))
)
) AS 3Log
FROM CT_ALL
WHERE CT_ALL.CTDate Between [forms].[FiltrationPlant].[StartDate]
And DateAdd('m', 1, ([Forms].[FiltrationPlant].[StartDate])) - 1;
JasonCanady
Jul 29, 2026Tin Contributor
Thank you so much for this. I still have one nagging question as to why when CT Required evaluated to a 10.0 it provided the correct answer but if it lowered to 9.9 it was false?!
Thank you so much again! I have the team testing now trying to push it to fail.
Have a great week!
Jason
- GustavBrockJul 29, 2026MVP
Probably when compared ad text, then 10.0 is smaller than 9.9 because it sorts from left to right.