In my query, I use the IIF
function to assign either "Before" or "After" to a field named BeforeOrAfter
using AS
.
When I run this query, however, the "Enter Parameter Value" dialog appears, requesting a value for BeforeOrAfter
. If I remove BeforeOrAfter DESC
from the ORDER BY
clause, I don't get the dialog.
Here is the offending query:
SELECT
d.Scenario,
e.Event,
IIF(d.LogTime < e.Time, 'Before','After') AS BeforeOrAfter,
d.HeartRate
FROM
Data d INNER JOIN
Events e ON d.Scenario = e.Scenario
WHERE
e.Include = Yes
ORDER BY
d.Scenario,
e.Id,
BeforeOrAfter DESC
Question: Why is my AS BeforeOrAfter
not being recognized by the ORDER BY
clause? Why does it ask me to enter a parameter value for "BeforeOrAfter" when I run this query?
Note: I tried using brackets, single quotes, double quotes, etc., but none of that made any difference.