How to call Stored Procedure in a View?

前端 未结 7 2190
灰色年华
灰色年华 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:13

    You would have to script the View like below. You would essentially write the results of your proc to a table var or temp table, then select into the view.

    Edit - If you can change your stored procedure to a Table Value function, it would eliminate the step of selecting to a temp table.

    **Edit 2 ** - Comments are correct that a sproc cannot be read into a view like I suggested. Instead, convert your proc to a table-value function as mentioned in other posts and select from that:

    create view sampleView
    as select field1, field2, ... 
    from dbo.MyTableValueFunction
    

    I apologize for the confusion

提交回复
热议问题