We are currently using Stored procs for most of our reporting, but I would like to have the flexibility of being able to join results sets with further criteria.
To do this with stored procs, I need to store the resultset from the storedproc in a temp tables as illustrated below:
CREATE TABLE #Top_1000_Customers (
CustomerCode BIGINT,
Firstname VARCHAR(100),
Surname VARCHAR(100),
State VARCHAR(),
MonthlySpend FLOAT)
INSERT INTO #Top_1000_Customers
EXEC FindTop1000Customers()
SELECT CustomerCode, Firstname, Surname, State, MonthlySpend float
FROM #Top_1000_Customers
WHERE State = 'VIC'
DROP TABLE #Top_1000_Customers
If I do this using a table valued function this code looks like:
SELECT FindTop1000Customers()
WHERE State='VIC'
If I want to I can even join the table valued function with another table.
This seems to be a bit more elegant than using stored procs and also looks like it would perform better - as it does not have to spool results to a temp table.
Are there any significant reasons why I would be better off using stored procs to accomplish these types of tasks instead of using table valued functions?