Reports: ALLDATA – Writing a “Select” Query

The following example is how to write a query selecting cases with the following criteria:

  • SNAP Section in Issuing status
  • Zip code – choose a common zip code from your country.
  1. Open the “AllData.mdb” file in the “Statistics” folder in your county “P” drive.
  2. On the Access toolbar, click on “Create”, then on “Query Design”
    query design selected
  3. Select the table(s) you want to query. Since we are looking for SNAP (Section C) data, for this example, we will select BCDEDATA.
    table selection menu
  4. Select the fields you want to see and enter the criteria you want to use to select the records:
    • Case Number – no criteria entered because we want to see all case numbers where the rest of the criteria is met.
    • CSECSTAT – we entered “I” because we want to see cases where the SNAP (Section C) is in “I” (Issuing) status
    • ZIPCODE – enter the first five digits of a zip code in your county, then an asterisk. For instance, if the zip code you wanted to search is “73000” enter 73000*. Remember to use a zip code from your country.
    • The asterisk is a wildcard. It means “any character”. Some zip codes are “zip+4”. In the example below we want to include every zip code that begins with 73546, but we don’t want to limit it to only 73546. We also want to pick up cases that have the +4. If you type the zip plus the asterisk, Access will add the word “like” for you.
    • In addition to the wildcard, you can use the following symbols or phrases when writing a query:
      • > = Greater Than
      • < = Less than
      • <> = not equal to
      • Is null (NOTE: be careful with this because “spaces” are not null, so if a field just has spaces – it’s not null)
      • Is not null
  5. Click on the Red Exclamation Point “Run” to see the query results.
  6. Query Results:
    query results
  7. Now we want to add additional criteria. We want to select only cases on which one of the SNAP recipients is a child age 10 or younger. Information about people and benefits is on the FDATA table. To add this table to the query, click on “View” then on “Design View”:
    design view
  8. Select the table with person data (FDATA) You can either double click on the table, or do a “right click” / show table” and select the table.
    FDATA screen
  9. Create a “relationship between the two tables. In ALLDATA the “CaseNum” field will always be the relationship field. All data will establish this relationship by drawing a line between “CaseNum” on each of the tables.
    CaseNum field
  10. Add the criteria to select the children who are “added to benefits” for SNAP. (S/A). This requires using a wildcard on either side of the benefit type. We also want to select only children born after 11/30/2004. (This example was created on 12/15/2014. Based on that, children born after 11/30/2004 are age 10 or younger).
    • Zip Code (from the BCDEDATA table) = the zip code you chose in the above step.
    • Benefit (from the FDATA table) = *s a*
    • Birthdate (from the FDATA table) = >11/30/2004. If you type >11/30/2004, Microsoft Access will change it to the correct format (with the # on either side of the date).

    table relations

  11. Click on the red exclamation point (Run!) to run the query
  12. View the result:

    You will notice that the “Benefit” field has the space for several benefit types. This is why we had to put the asterisk on either side of our “S A”. Any time you want to limit a query by benefit type, be sure to put an asterisk on either side of the benefit type. For instance *M A* instead of M A. or *C A* instead of C A.

    You will also notice that some cases are listed several times. This is because a case is listed for each child born after 11/30/2004. If you wanted to list each case that included a child age 10 or under only one time you would have to write a “Select Distinct” query, and we are not going to cover that in these instructions. There are many websites that can guide you through that process.
    Alldata 8

Writing a “Select” Query Using “and”:

In this example we are going to write a query selecting cases with the following criteria:

  • SNAP Section in Issuing status and
  • Section B in Issuing status

Alldata 9
If the two conditions are on the same line, it means “and”. This query is saying that

  • CSECSTAT is “I” and
  • BSECSTAT is “I”

Writing a “Select” Query Using “or”:

In this example we are going to write a query selecting cases with the following criteria:

  • • Section B in Issuing Status, or
  • • Section C in Issuing Status and Child receiving SNAP is age 10 or younger

Alldata 10
If the two conditions are on the same line, it means “and”. This query is saying that

  • CSECSTAT is “I” or
  • BSECSTAT is “I” and Person is added to SNAP (S/A) and Person has Date of Birth after 11/30/2004

When writing an “or” query you must be sure to repeat the criteria that applies to either statement. In this query the zip code is repeated on each line because it applies to each condition.

If you are looking for two possible values in the same field you can put the “or” statement in the criteria for that field. This query is for open SNAP cases with a zip code of 73099 or 73127:
Alldata 11

Was this article helpful?

Comments or Suggestions?

We want Quest to be your source for important information that you need to succeed at in your work but we need your help:

Was this article helpful? Was it missing something you needed to get the job done?

Tell us what you think, what you know about this article. What are we doing well, and what we could do better.

All fields are required.