Beruflich Dokumente
Kultur Dokumente
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
Now, let's say we've created the Movies table and, using the appropriate Form, we've input the movies
that we c arry.
Hopefully we have thousands of entries in that table to give our customers the greatest choice possible.
And, if you look at the example below you will note that we usually have several copies of each movie in
stoc k. Eac h VHS tape or DVD c arries a different item number but the rest of the information has simply
been copied and pasted from one to the other.
www.profsr.com/access/accless07.htm 1/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
If a customer comes in and wants to know what we have starring Tom Cruise or direc ted
by Spielberg or released in 1995, all those are queries. As long as the information is stored
in the database we can get it.
We will also have queries that are repeated all the time and we will have to take care of
those also:
"What were the sales figures for last month, for last year?"
"How many customers do we have and what is their average age? Are there more men or
women?"
The simplest query would return a list of a whole table. But we rarely need to see all the
columns in a table.
The first thing we do when designing a query is to determine what columns or fields we
want to see. Usually just enough to desc ribe eac h record that will display.
www.profsr.com/access/accless07.htm 2/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
www.profsr.com/access/accless07.htm 3/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
There is a simple way to correct that and that's to use the Properties of the Query, as
shown below:
www.profsr.com/access/accless07.htm 4/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
I c an now save the Query so that if the question ever c omes up again I only have to go
to the Query objects and open the query that I had saved.
I'll give it a name that will remind me of what it does, not just Query1.
Just to remind you again: the query results are not saved here. Only the structure of the
query is saved. If we add a bunch of new movies before we run the query again, all those
movies, if they apply, will show up next time.
Specifying criteria
You may have noticed in all the pics above that the title bar always refers to "Select
Query". That means that we are selec ting something. In fact, we usually select some
records from the table. We rarely have to see all the movies, or all the customers.
To select some records we will use the Criteria line in the query to specify a condition
for a record to be included in the result.
For example: Show me all Tom Cruise movies in stock. Note: in all these I will use the
Unique Values property so that I don't get 4 or 5 repetitions of the same movie.
www.profsr.com/access/accless07.htm 5/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
To define criteria we use comparison operators. These are the signs most people are
familiar with from programming, and there are a few new ones.
= equal
greater or
>=
equal
reverse
not
condition
like
between
www.profsr.com/access/accless07.htm 6/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
Examples:
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
All movies with a value of $25 or more.
m_Cost >= 25
Access is very flexible. However you should get into the habit of using punctuation
correctly.
Usually, text fields, or strings, are enclosed in quotes: "Tom Cruise", dates are enclosed in
number signs: #2000-01-01# and numbers are enc losed in nothing.
The like operator is very useful and is used extensively when working with text fields.
It is used in combination with the * , the wildcard character.
If there are criteria in 2 columns, both have to be true. This is an AND condition.
www.profsr.com/access/accless07.htm 7/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
www.profsr.com/access/accless07.htm 8/9
F -X C h a n ge F -X C h a n ge
PD PD
1/5/2010 Develop Business applications with Micr…
!
W
W
O
O
N
N
y
y
bu
bu
to
to
k
k
lic
lic
Next week: More complex Queries. See you then!
C
C
w
w
m
m
w w
w
w
o
o
.d o .c .d o .c
c u -tr a c k c u -tr a c k
www.profsr.com/access/accless07.htm 9/9