sql server - Have table-valued function in T-SQL return table with variable number of columns -


is possible have table-valued function in t-sql return table variable number of columns?
column names may 1, 2, …, n.

right have "string split" function returns single-columned 1 x n table, , pivot table afterwards n x 1 table, i'd rather streamline process returning correct table format begin with.

i intend use clr procedure in c# function, don't know how set user-defined function return data in format want: variable number of columns, dependent on input string.

it not possible return non-static result set table-valued function (tvf), whether written in t-sql or .net / sqlclr. stored procedures can dynamically create result set.

basically, function needs return consistent result type, whether scalar value or collection (i.e. result set).

however, in sqlclr stored procedure, can create dynamic result set via sqlmetadata. long don't have explicit need select ... from it, maybe stored procedure work.

of course, might able away doing in t-sql, using dynamic sql construct select statement based on output of split function.

a lot of comes down exact context in functionality needs used.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -