user4804987
user4804987

Reputation:

Order by statement in Microsoft Access with parameter

I have a table in Microsoft Access named tblPerson with three column:

  1. ID
  2. Name
  3. Score

How I can create a query that define ordering column with parameter?

Upvotes: 0

Views: 300

Answers (1)

Gustav
Gustav

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

Related Questions