Create a view from results of a Stored Procedure

  • I have a stored procedure that does a dynamic pivot on a table where the number of columns is unkown. I would like to display use the results of this procedure in a view that could then be combined with another view. Is it possible to return the results of a stored proc in a view?

    Here is my procedure call:

    exec

    uDynamicPivot 'vCor_AccumulatorCheckDetail','US_Paycheck_ID','sum','AccumulatorAmount','AccumulatorName',',106'

    thanks

  • No, you cannot use a stored procedure in a view.

    However, what you can do is to create a table and then use INSERT..EXEC to dump the results or your stored procedure into that table. Plus you could then put a View on that table, but of course that would be static.

    One other thing that you can do is to change your stored procedure into a Table-valued UDF, and then call your function from a View that you create.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply