1

如何调用在存储过程中返回表的函数。

我想在存储过程中使用从函数返回的表。

它是怎么做的?

4

1 回答 1

2

您的问题并不具体,可以通过不同的方式调用表值函数(取决于需要):

create procedure Test
(
    @someParam varchar(50),
    @someParam2 varchar(50)
)
as
begin
    set nocount on

    ...

    select tf.Col1, tf.Col2, tf.Col3, tf.Col4, tf.Col5
    from tableValuedFunction0() tf

    select tf.Col1, tf.Col2
    from tableValuedFunction1(@someParam) tf

    create table #temp (...)

    insert into #temp (...)
    select tf.Col1, tf.Col2, tf.Col3
    from tableValuedFunction2(@someParam, @someParam2) tf

    create table #temp2 (...)

    insert into #temp2 (...)
    select t.SomeCol, tf.Col1, tf.Col2
    from someTable t
        cross apply tableValuedFunction3(@someParam2, t.SomeOtherCol) tf

    update t
    set t.SomeCol = tf.Value
    from someOtherTable t
        join tableValuedFunction4(@someParam2) tf on tf.SomeOtherCol = t.SomeOtherCol

end
于 2013-09-05T13:07:17.957 回答