Query Attributes task |
|
Release 9.3 |
The Query Attributes task helps users select or view certain data on the map based on that data's attributes. A Query Attributes task creates a single query on one map layer. However, the query can have compound criteria. For example, you can define a query on a cities layer that selects cities with a population greater than a value entered by the user and with a name that begins with a value entered by the user.
When you configure the Query Attributes task, you create an easy-to-understand form that will guide the user through the process of making the query. This way, users of your application will not have to know the details about the dataset, nor will they have to construct a Structured Query Language (SQL) statement, to query the data.
For example, suppose you wanted users to select U.S. counties by entering a state name and a minimum average household size. A SQL expression for this selection might look something like this: SELECT * FROM counties.sdc.counties WHERE: "STATE_NAME" = 'Idaho' AND "AVE_HH_SZ" > 3.0. The users of your Web application might not know the field names of your data or how to write a SQL statement. You can help them by using the Query Attributes task to create an easy-to-read form with text like the following: "I want to select counties in the state of: (user picks a state from a drop-down list) whose average household size is greater than or equal to: (user types a number in a text box)."
After adding a Query Attributes task to your application, click the Configure button to display the task configuration settings. You use this dialog box to build the query and to specify the wording that a user sees when the task is displayed. You can also adjust how the results will be displayed.
The General tab allows you to fine-tune the wording that users will see when they run your task. You can change the following:
Use the Settings tab to build your query. After selecting a map service and a layer to query, click the Add button to add a condition to your query. You can add multiple conditions to create a compound query. If you're new to SQL or you need a review, a good place to start is About building an SQL expression in the ArcGIS Desktop Help.
The example above shows a query condition allowing the user to enter a value and find counties with a population greater than that value.
Remember the following points when setting up a Query Attributes task:
By default, ArcGIS Server map services limit the number of records returned by a query to 500 records. This is important to remember when configuring the task because if you click the 'Get Sample Values' button, only the first 500 records will be scanned for unique values. To change this behavior, you need to manually edit the configuration file and raise the MaxRecordCount property to the number of records from which you want to retrieve sample values. Then stop and start the service. See the ArcGIS Server Help topic "Service configuration files" for instructions on editing configuration files.
Note that by default, the Query Attributes task limits results to 50, so if you keep this value and you do not need to use "Get Sample Values", you will not need to edit the service configuration file.
Queries that return more than 2000 records require the software to create scratch workspaces in your system TEMP directory to manage the result records. This can cause performance to degrade.
Constructing a SQL expression for date/time fields requires additional formatting depending on what database your data is stored in. For example, when your data is in a personal geodatabase, you need to enclose the date in # signs.
If you don't want users to have to enter the # sign or any other special formatting whenever they query dates, you can make the special formatting part of the expression. To do this you need to edit the task in Visual Studio and choose the Custom Where Expression option. The following expression queries two date fields in a personal geodatabase, represented by {0} and {1}:
mydate >= #{0}# AND mydate <= #{1}#
Other databases do not require the # signs, but require other special syntax. To make sure you've structured your expression correctly, see the "Dates" section of the SQL reference topic in the ArcGIS Desktop Help.
Use the Results tab to configure how task results will appear. It's helpful to know the following: