Skip to main content
Engineering LibreTexts

6.5: Parameter Query

  • Page ID
    15528
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    If you need a query but the criteria will not be known until runtime you use a Parameter Query. A parameter query is one where, on the Criteria line for some field, one types square braces [] and inside the [] one types a prompt for the user who runs the query. When a user runs a parameterized query, MS Access will show the user the prompt and waits for the user to respond with a value for the parameter – MS Access replaces parameters with the user-supplied values just before it executes the query.

    Example

    Suppose a user in the University database needs a list of courses having a specific value for credit hours. The query below has a parameter in the criteria line for creditHours:

    Parameter query.
    Figure \(\PageIndex{1}\): Parameter query.

    When the query is run, the query is temporarily suspended while the user is prompted with the message as given in the square braces []. Once the user responds to the prompt the running of the query continues with the value the user entered as the criteria value.

    Exercises

    Exercise \(\PageIndex{1}\)

    Consider the University database.

    1. Create a query to list all courses in a department (for which the user supplies the department code).
    2. Create a query to list all course titles where the user supplies both the department code and the credit hours. Note that two separate criteria, each with their own parameter, must be specified.

    Exercise \(\PageIndex{2}\)

    Consider the Company database.

    1. Write a query to list the employees who manage a department where the department code is provided by the person running the query.
    2. Write a query to list all employees in some department where the department code is provided by the person running the query.
    3. Modify the employee data in the Company database so at least two employees have the same first and last names. Develop a query that lists all employees having a specific first name and last name that will be specified by the end user.

    Exercise \(\PageIndex{3}\)

    Consider the Genealogy database.

    1. Create a query with two parameters: a start date and an end date. The query will list all persons whose birth dates fall in the range from start date to end date.

    Exercise \(\PageIndex{4}\)

    Consider the Library database.

    1. Write a query to list books due on a specific date (a parameter).
    2. Write a query to list books written by a specific author (a parameter).

    This page titled 6.5: Parameter Query is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ron McFadyen.

    • Was this article helpful?