dynamic sql functionality with filter capabilities