I need to write a Table – valued function from which I can acquire a table result set with different structure each time.
another thing is that I need to declare variables inside my function .
I’ve search for more that 3 hours but I could not find anything regarding this issue.
Is there any way to do that?
Thanks in advance
The schema (column names, data types, etc) returned by a TVF (or view) is determined when the object is created. It cannot be dynamic, varying at execution time.
Views and TVFs should be used logically much like a table, where the schema is a contract between the database and application. It will wreak havoc if columns come and go or change between executions.