day 17: access chapter 2-3 rahul kavi [email protected] [email protected] october 17,...

18
DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI [email protected] October 17, 2013 1

Upload: regina-cole

Post on 17-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

DAY 17:ACCESS CHAPTER 2-3

RAHUL [email protected]

October 17, 2013

1

Page 2: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

2

LAST CLASS

• Relationship Types– Many-to-one– One-to-one– Many-to-many

• Calculated Fields• Relationship Manager

Page 3: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

3

TODAY’S CLASS

• Queries• Calculated Fields in Queries• Basic Queries• Multi-table queries

Page 4: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

QUERIES

• A Query is a question one asks about the data stored in a database

• Access responds by displaying specific records that answer the question

• In creating a query, we tell access which fields are needed(in one or more tables) and what criteria needs to be met

Page 5: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

5

CALCULATED FIELDS IN QUERIES

• New fields can be calculated from existing fields using an expression

• Expressions can include the following:– Identifiers (names of fields)– Arithmetic operators (*, +, etc.)– Functions (Date(), IIf())– Constants (numbers such as 12 or 0.35)

Page 6: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

6

EXPRESSION SYNTAX

• You should give calculated fields a name by prefixing the expression with the name followed by a colon

• Example:– NewBalance: [Balance] + [MonthlyInterest]

• After the colon, you can use any functions or mathematical operators to calculate the value based on existing fields and/or constants

Page 7: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

7

EXPRESSION BUILDER

• Right click the field->Builder• Select the field, then

– Query Tools->Design->Query Setup->Builder

• Expression builder provides graphical tools for looking up operators (functions and arithmetic operators) and operands (existing fields, constants)

Page 8: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

8

FUNCTIONS

• Like Excel, Access has many functions for performing calculations– PMT– IIF– DateDiff

Page 9: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

9

PMT

• Identical to PMT in Excel– Pmt(rate, num_periods, present_value)

• Rate is the interest rate per payment period• Num_periods is the number of payment periods• Present_value is the present value of the loan

(which should be negative for most situations)

Page 10: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

10

IIF

• IIF is the Access equivalent of IF in Excel• Iif(expression, truepart, falsepart)

– Expression is a comparison that is evaluated– If expression is true, Iif returns the value of

truepart– If expression is false, Iif returns the value of

falsepart

Page 11: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

11

DATE ARITHMETIC• Date()- returns the current date• Now()- returns the current date

and time• DateDiff(format, date1, date2)

– Format: Result in years, seconds, quarters, etc

– Date1 and Date2 specifies the date for which the difference has to be calculated

yyyy Yearq Quarterm Monthy Day of

yeard Dayw Weekdayww Weekh Hourn Minutes Second

Page 12: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

12

AGGREGATION (SUMMARY QUERIES)

• Summary queries allow you to calculate summary statistics from your data– Avg, Count, Max, Min, StDev, Var, Sum

• These functions can be used as calculated fields

Page 13: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

13

TOTALS QUERIES

• Aggregation can also be done as a totals query

• Query Tools->Design->Show/Hide->Totals• Select how you would like to aggregate

each field

Page 14: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

14

GROUP BY

• Group By groups the data before the aggregation functions are applied

• This allows you to find summary statistics for each group

Page 15: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

15

LOOKUP FIELDS

• Lookup fields are a nice way of hiding the foreign keys

• Instead of displaying the foreign key, the lookup field looks up the record for that key and displays whatever fields you set up

• Lookup fields also provide a dropdown to select the record you want to establish the relationship with

• Internally, it is still just stored as the foreign key

Page 16: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

16

CALCULATED FIELDS

• Calculated fields can also be added to table definitions for commonly used calculations

• Simply select Calculated as the field type and input your expression into expression builder

Page 17: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1

17

NEXT CLASS

• Expression Builder• Forms

– Create, modify– Sorting– Form Sections– Control Types

• Reports– Create, modify– Sorting– Report sections– Control Types

Page 18: DAY 17: ACCESS CHAPTER 2-3 RAHUL KAVI Rahul.Kavi@mail.wvu.edu Rahul.Kavi@mail.wvu.edu October 17, 2013 1