Fixed parameter generation and added SQL query helper