Medical data are characterized by complex taxonomies and evolving terminology. Questions that clinicians, medical administrators, and researchers may wish to answer using medical databases are not easily formulated as SQL queries. In this paper we describe a graphical tool that facilitates formulation of ad hoc questions as SQL queries. This tool manages multiple attribute hierarchies and creates SQL query strings by navigating through the hierarchies. This interactive tool has been optimized using indexing to improve the overall speed of the query building and the data retrieval process. Indexed queries performed 5 to 100 times faster than query strings. However, query string generation time depends on the size of the taxonomies describing the hierarchies, while the index generation time depends on the size of the data warehouse.