write the query in database check point and pass it as parameter, your query looks dynamic