Saturday, July 2, 2016

ArcMap Tool: Selection To SQL Query

When dealing with larger datasets in ArcMap, it's often useful to just view a subset of features.  Just selecting them and viewing them is often not an adequate solution--you can lose the selection by selecting another feature, the other features in the feature class can clutter the view, etc.  One possible solution is to use the "Create Layer From Selected Features" functionality ArcMap provides.


But say you want to quickly share this subset of features with a colleague who already has access to the dataset, without sharing an MXD or a feature class, which would add to unnecessary data clutter.  The easiest thing to do would be to create a SQL query for these features, functionality that ArcMap doesn't provide.  I created the Selection to SQL Query tool for this purpose.

This zip file contains the script and toolbox versions for ArcMap 10, 10.1/10.2 and 10.3.  I've only tested the 10.3 toolbox on 10.3.1.  Let me know if there are any suggestions/requests for improvements!

A couple disclaimers :)
  1. The tool currently does not support creating queries from fields of the following types: blob, date, geometry, GUID, raster
  2. Use this tool at your own risk! I haven't done significant testing, although I use it regularly.
  3. The tool has been used primarily with ArcMap 10.3.1


Tool Directions:

  1. Make a selection in a table or feature class in your ArcMap session.

    The first screenshot shows the selection which the following screenshots are based on.

  2. Select the table or feature class as the first parameter.  Note: you have to use the table/feature layer in the Table of Contents as input, don't drag/drop from the ArcCatalog window.
  3. Select a field whose values will be used to create the SQL query.
  4. Check the checkbox if you want to apply the query as a Definition Query.

  5. Check Message in the Results window (Geoprocessing > Results) for the query.

    The below screenshot shows the Definition Query applied for the example.