140 likes | 218 Views
Query Lab 6/17/2014. Agenda Practice writing queries against Belmont sample database Answer questions about Access Project Part 2. To Begin:. Copy (DON’T OPEN) the QueryBelmont database from K:IS201IS201-HilferLabClass Create a customer query:
E N D
Query Lab 6/17/2014 • Agenda • Practice writing queries against Belmont sample database • Answer questions about Access Project Part 2
To Begin: • Copy (DON’T OPEN) the QueryBelmont database from K:\IS201\IS201-Hilfer\LabClass • Create a customer query: • Create a query to show customer information: company, name (concatenated as one field), phone number, city and state • Save this query as qryCustomers
Add Criteria • Make a copy of qryCustomers, name it qry49341Customers • Modify the query to only display customers with a Zip code of 49341 • Don’t display the zip code in the results • You should have 2 result records
Working with dates • Create a query that shows all contracts signed in August 2013. • Name this query qryContracts • How would you modify this to show all August contracts regardless of year?
Using And • Create a query that lists only contracts that are greater than or equal to $50,000 And that were signed in 2013 • Name this query qryAndExample
Using OR • Modify qryAndExample to show all contracts that are greater than or equal to $50,000 Or that were signed in 2013. • Name this query qryORExample
IIF • The IIF function has three arguments: • Expression • True Part • False Part
Using IIF • Create a query that shows ContractNum, SigningDate, Contract Amount and a Contract Size column that displays: • “Large Contract” if the contract is greater than or equal to $50,000. • “Small Contract” if the contract is less than $50,000.
Using IsNull • Copy qryCustomer and name it qryIsNull • Modify the query to not show the company and customer name in separate columns. Instead show the company name and if the company name is null show the customer’s concatenated name.
Queries with multiple tables (joins) • When querying data from multiple tables it is called “joining tables”. • Only include the tables in the query that are needed in the query, all relationships must show up. • Create a query showing customer name, Invlice date, invoice item and invoice amount. • Why do you end up with a strange result?
Joins Continued • Add the Contract table to your query so that the relationship exists. • Rerun the query.
Aggregate Queries • Create a query that returns one row: • The number of invoices • The total of all invoice amounts • The largest invoice • The smallest invoice • The average invoice amount • Name this query qryAggregate
Aggregate Queries Cont • Modify qryAggregate to show the same information grouped by Contract number • Name this query qryGroupBy
Tips • Only include tables you are using in the query design. • If you are joining tables (querying data from multiple tables), the tables must be related in the query design. • Wait to hide fields until the query is working. • Do not use the names of hidden fields in a query – you will end up with a parameter query.