Query processing systems in wireless sensor networks usually support tasks such as data acquisition, data aggregation, and event‐based query. The performances of query processing with these tasks are greatly varied according to different routing protocols. Most existing data query systems usually use one routing protocol to deal with all kinds of queries. This work demonstrates that proper selection of routing protocols can improve the performance of query processing. We propose a dynamic routing layer that makes protocol selection on the basis of query tasks and can automatically switch between different routing protocols. Simulation results show that dynamic routing scheme is more energy efficient than single routing protocol. Copyright © 2012 John Wiley & Sons, Ltd.