How to write SQL Query to return output parameters