How to call Stored Procedure in a View?

前端 未结 7 2200
灰色年华
灰色年华 2020-12-01 07:39

How would I call a Stored Procedure that returns data in a View? Is this even possible?

7条回答
  •  隐瞒了意图╮
    2020-12-01 08:15

    I was able to call stored procedure in a view (SQL Server 2005).

    CREATE FUNCTION [dbo].[dimMeasure] 
       RETURNS  TABLE  AS
    
        (
         SELECT * FROM OPENROWSET('SQLNCLI', 'Server=localhost; Trusted_Connection=yes;', 'exec ceaw.dbo.sp_dimMeasure2')
        )
    RETURN
    GO
    

    Inside stored procedure we need to set:

    set nocount on
    SET FMTONLY OFF
    
    CREATE VIEW [dbo].[dimMeasure]
    AS
    
    SELECT * FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;', 'exec ceaw.dbo.sp_dimMeasure2')
    
    GO
    

提交回复
热议问题