I would suggest to create a function which will return object and gets the sql to be executed and the type of data to be return back. And you could cast it back after calling the function