-1

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

  • Please it is not clear what are you trying to achieve. Try to improve your question by adding some example. – McNets Oct 8 '18 at 7:15
  • Sounds like you want a stored procedure using dynamic SQL, not a table-valued function (functions can't use dynamic SQL, and inline TVFs - the only ones that benefit performance-wise from being functions - can't use local variables). – Aaron Bertrand Oct 8 '18 at 13:26
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.