I need to create a FUNCTION that accepts a SQL statement as a parameter and an index as the other parameter. The SQL statement will return a single column with multiple rows. I want the function to pass back the 1st value (row), or 2nd value, or 3rd value depending on the index parameter.
I don't think I can pass in the SQL statement as a VARCHAR and execute it in a SQL function. Can I pass in the results of the SQL statement as a table and have the function return the row identified by the index parameter?
I need this to be a function because I want to call it within a column of an outer SQL statement.
Thanks,
Mark