Browsing with dynamic columns in SQL Server

How to create a view in SQL Server where columns are defined and displayed according to the value stored in another table. These columns are calculated in almost the same way by the function, but their number is specified from a different table record.

+3


source to share


2 answers


This is not possible with a view because SQL Server queries are always statically typed in the sense that both columns, names, and types are statically known at runtime.

Dynamic columns require dynamic SQL.



Views do not support dynamic SQL. You should find another way to return the data, perhaps with one row in each logical column.

+4


source


You can create a built-in table scoring function and define your fields and return the table and then call the function inside your view.



0


source







All Articles