Parameters Query in Access

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

Chapter 10

Parameters query in Access

Objectives
Describe

parameter query
Using parameter query in Access

What is parameter query?


There

are no variables in SQL. Instead


known as variable, parameters query is
use to pass data to a query.
You usually write a parameter query for an
end user to run. At runtime, the end user is
asked to provide specific values for all the
variables.
These values are placed into the SQL
statement before it is sent to the DBMS.

What is parameter query?


In

a parameter query, the variables do not


belong to the SQL itself
They belong to the environment that
people use to submit SQL queries.
In Access, it is in the GUI layer, before the
SQL query sent to the JET database
engine for processing.

Parameter query in Access


Access

automatically prompts you for the


value of any variable it does not
recognize.
It is turned to prompt for parameter values.
If you misspell the name of a column, it
prompts you to enter a value for that
column.

Parameter query in Access


Write a procedure in Access that will ask for a student id.
After the user enters the id, the procedure finds the
information about that student in the student table.

SELECT *
from Student
where StudId = [Enter a student id];
Once this query is executed, Access will prompt for user to enter the
student id. The following pop-up window will be appearing in the
Access. The sentence Enter a student id will become the
parameter query for this query.

Parameter query in Access

Once a value has been entered, press OK and the result will be shown.

Parameter query in Access


Output:
The information for student S007 will be display as the result.
StudID

LastName

FirstName

Gender

S007

Tham

Tian En

DateEnrolled

GPA

19-Sep-03

3.89

GroupLeader

CourseID
DCS

Access with two parameters


When

there are two or more parameters


within a query in Access, the same value
is placed in all the parameters with the
same name.
If you want to put different values in two
parameters, you must give different
names.
The name of the parameter comes from
the text that it prompts for.

Access with two parameters


Ask the user to enter a beginning date and an ending date.
Then shows all the students that enrolled between those
two dates.
WITH ERROR
SELECT *
from Student
where DateEnrolled between [date] and [date];
With this code, there will be only one prompt for date. The same value
will be placed into both parameters. The query returns only the rows
for the people hired on that one date.

Access with two parameters


THE CORRECT SQL statement
SELECT *
from Student
where DateEnrolled between [low date] and [high date];
From the above query, Access will prompt the user to enter 2 values. The
first prompt required the user to enter a date for low date and another
for high date.

Access with two parameters


Output:
StudID

LastName

FirstName

Gender

DateEnrolled

GPA

GroupLeader

CourseID

S001

Bartell

Joseph P.

15-Feb-02

3.21 S005

DCS

S003

Lee

Choy Yan

05-Jan-02

3.82 S016

DIT

S009

Nicosia

Anthony L.

01-Feb-02

3.11 S005

DICT

S014

Williams

Jason R.

12-Dec-02

2.74 S010

DCS

S015

Chan

Xi Xi

12-Dec-02

3.12 S016

DIC

Limitations on parameters in
Access
Only

use a parameter in a query to hold


the place for a specific value, such as
100,Wilson, or Sept 20, 2005.
You cannot use a parameter in the place
of a column name or a table name.
A same parameter only can be use in a
query, not across multiple-query. This is
because the SQL window only allows you
to enter one query at a time.

Summary
Ways

to create parameter query in

Access
Understand how the value is being
pass to the query

You might also like