Get Started with Ad-hoc Query

Query is a powerful tool you can use to help filter and group records. While it can be a bit intimidating at first, this guide will help you get started.

Query basics

With Query, you can group records according to any criteria you want. Before you begin building your query, think about what records you want to see. Form a statement, such as “I want to see the names of all constituents who are members and have given a gift this month, listed alphabetically by last name.” Be as specific as possible — you can even write down your statement to help.

Tip: Queries are all about fields. Remember when you entered a birth date on a constituent record? That’s the Constituents: Birth date field in a query.

Build a query

At the simplest level, a query answers four basic questions, which correspond to the four main components of a query: source view, filters, output, and sort/group options.

  1. What type of info or records are you looking for?

  2. What specific parameters do you have?

  3. What do you want to see in the output?

  4. How do you want the results displayed?

Let's break down the following statement to see which parts match each of the four questions: I want to see the names of all constituents who are members and have given a gift this month, listed alphabetically by last name.

  • The names — This tells us we want to see names in the results. This is the query’s Output.

  • Of all constituents — This tells us that we need a constituent query, which means we’ll use the Constituents Source View to create the query.

  • Who are members and have given a gift this month — We want to see members, so we can use the constituency as a Filter. If the constituency is equal to member, we match on the first part. So let’s look at the rest of it. “...and have given a gift this month” makes things a little more complicated. So we’ll need another filter to find the gifts in that time frame.

  • Listed alphabetically by last name — This tells us how we want to Sort the results.

Now let’s look at each question individually so we can learn about the parts of the query and how we can build it.

View results

Before we check our results, let’s review our original statement: We want to see the names of all constituents who are members and have given a gift this month, listed alphabetically by last name. Plus we want to see the amount of their gifts this month summarized instead of seeing each gift separately.

Now we can go to the Preview results tab to preview the query output. check to see if things look okay, but . . . wait! The names are sorted alphabetically, but by the whole name, not the last name! So we have Christopher Young before Elizabeth Ashton—not exactly what we were expecting.

Remember how we talked about getting to the end and realizing we need to take a step or two back to add other fields to the output or change the sort order to see exactly what we want?

  1. Return to the Select filter and output fields tab and add the last name to the Results fields to display section. We’re looking for the Constituent: Last/Organization/Group/Household name field.

  2. Select the Set sort and group options tab to sort by last name only. Let’s make those changes and take another look at the Preview results tab.

This looks great! It’s just what we were expecting, which means we built our query correctly! Now we can let our membership director know about each of these loyal and generous members! If she wants to use query results elsewhere in the program, we can create a selection of the results for her. Because the selection is based on the record ID—of the constituents who are members in our case—a mailing process will have access to all the other information about the constituents, such as addresses. So we wouldn’t need to include that information as output in the query. See Create Selections from Queries for more information, including special rules for summarized fields!

Note: If we want to use our query results outside of the program, like in a spreadsheet, we can export the results. However, if we do this, we get exactly what shows up on the Preview results tab. If we summarized revenue, we’ll have only the total and not each individual gift. If we didn’t include a date field, then no date. Check out Export Queries for information on how to export our results.

Now that we have the query squared away, let's give it a name and save it so we can find it again in the future. On the Set save options tab, we can name the query and describe its criteria and output. We can also assign it a category or folder to organize it with similar membership queries. Before we save the query, we can also select to create that selection for the membership director and select whether to allow other users to update the query.