I work for a public school system and have to create behavior reports for various things. I have about a dozen reports where the data is generated via stored procedures and pretty much retrieve the same base data. I'd like to create a Table-Valued Function so that each report is pulling the same base dataset to work with.
I have a student table that has columns such as schoolYear, Grade, schoolID, etc. The key is enrollmentID. I'm trying to determine which is more efficient, to return all the fields I'll be working with from the student table (schoolYear, grade, etc) or just return the key (enrollmentID) and then join it back with the student table in the query that is calling the function.
On one hand, it seems redundant to join the student table in both the function and the stored procedure that is calling the function. On the other hand, thousands of records are potentially returning and it seems like in the past I've noticed significant lag if I'm trying to return a lot of data from a function.
Is there a best-practice on how to best use table-valued functions? As always your help is greatly appreciated!