【问题标题】:How call Table Values function from stored procedure如何从存储过程中调用表值函数
【发布时间】:2013-09-05 12:42:12
【问题描述】:

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

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

它是怎么做的?

【问题讨论】:

    标签: sql-server-2008 stored-procedures table-valued-parameters table-variable


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 2011-04-29
      • 2020-01-09
      • 2017-04-23
      相关资源
      最近更新 更多