Reputation:
I have a table in Microsoft Access named tblPerson
with three column:
How I can create a query that define ordering column with parameter?
Upvotes: 0
Views: 300
Reputation: 56016
You can use the Choose function:
SELECT tblPerson.Id, tblPerson.Name, tblPerson.Score
FROM tblPerson
ORDER BY
Val(Choose([OrderBy],[ID],[Name],[Score])),
Choose([OrderBy],[ID],[Name],[Score]);
where OrderBy is your parameter from 1 to 3.
Note that fields will be sorted first as numerics than as strings.
Upvotes: 1