It is better to have your query in stored procedure. It would help in avoiding deployments in case of a change.
I do not have a choice to create stored procedure. I want to pull data using a SQL query.
you can try to create a relationship in db adapter configuration wizard rather to use custom sql query.