Select @var = temporal table result from function SQL Server? -


if have function returns temporal table, how set var in sql server saves it?

if result of function like:

temp table     item1 item2...itemn         1     2...    n 

is valid?

select @table = * dbo.some_function() 

??

if possible, make example, of how use @table var knowing values?

if not possible, how can access temp table function returns??

if function returning table, should able have:

insert @table (col1, col2) select * dbo.some_function() 

you'd need specify columns you're going using either insert or select portion of statement.

update:

here's i've come can find out columns. first part enabling server can return , use stored procs normal table (check dba or whoever runs server they're ok these options being turned on). select resultset temp table, run sp_columns stored proc in tempdb , insert temp table (which drop). way, @ least know columns you've got, , can possibly use make easier work dynamic column names perhaps.

sp_configure 'show advanced options', 1 go  reconfigure go  sp_configure 'ad hoc distributed queries', 1 go  reconfigure go  select * #itemstable dbo.some_function()  select * #columns openrowset('sqlncli', 'server=(local);trusted_connection=yes;', 'exec tempdb..sp_columns ''#itemstable''')  select column_name #columns  drop table #columns 

another update:

if want list of columns table in database, use query:

select [name] sys.columns object_id = (select object_id sys.tables [name] = 'tablename') 

however! if you're going running query , creating tables of varying sizes many times day, suggest stick temp tables. way won't writing unnecessarily database (except tempdb). if reason need permanent tables created each time, then, guess that's fine too!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -