• Almost loathe to answer it, but I never know what the needs are.

    It is possible. Perhaps you're trying to avoid the poorly performing table variables in 2005+ and use a reporting tool that won't submit proc calls or something. Who knows.

    You shouldn't call procedures through functions, and this approach REALLY isn't advised, but one method of doing it (there are several) using only sql, in an imaginary scenario, without using any table variables is:

    1) Create your stored procedure, accepting whatever paramters are needed. In the stored procedure, implement a "tidyup" routine for previous result sets. Output the data to a perm table. The stored procedure then acts as a specific result set refresh mechanism. A status table could store the last refresh dates, status etc.

    2) Create a table function. Use command shell (ewww) to call the stored procedure through osql, returning the current status of that result set.

    3) Run a report against the perm table, to retrieve data, or include the function to refresh it.

    Did it once on my dev box, just for a laugh and it does work. Don't think any of it is best practise, but on principle I had to prove it could be done 😉

    And yes, depending on the complexity and size of the result set, you will most likely notice a significant improvement in speed, over table variables for derived data, plus the result set is reusable if stored, thus potentially cutting overheads.

    If you focus on those points and ignore the huge gaping holes *cough security cough* and complete lack of best practise, it's great!