sql - Calling table-valued-function for each result in query -


say had query this:

select x table y = 'z' 

how execute stored procedure using each x above query parameter?

update

i have changed sp table-valued function instead. each call function return table. need store these results in perhaps temp table , have sp return table.

solution

finally managed work @cyberkiwi. here final solution:

declare @fields table (     field int)  insert @fields (x) select * tvf_getfields(@someidentifier) select * @fields cross apply dbo.tvf_dosomethingwitheachfield([@fields].field) 

you can generate batch statement out of , exec it

declare @sql nvarchar(max)  select @sql = coalesce(@sql + ';', '')               + 'exec sprocname ' + quotename(afield, '''') table afield2 = 'someidentifier'   , afield not null  exec (@sql) 

before edit (to tvf), have changed sp continue populate temp table.

post-edit tvf, can use cross apply:

select f.* tbl cross apply dbo.tvfname(tbl.afield) f tbl.afield2 = 'someidentifier' 

which returns "table results" each invocation of tbl.afield single result set


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -