简体   繁体   中英

Why am I getting “Enter Parameter Value” when running my MS Access query?

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.

I beleive Access can't handle the alias feature, so you'll have to copy your IIF-block down into the Order By -clause. Or create a subquery (and then you might even find yourself forced to even not be able to use parantheses if your Access version isn't among the newest two or so).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM