Exec Stored Procedure from a View

  • Hello,

    This is going to be a dumb question, but how do I execute a Stored Procedure from a View?

    I have a View called WOApproveAccess_vw and I need to execute a Stored Procedure called WOApproveAccess2_sp. There are no parameters in the SP.

    I was not able to find a clear explanation for how to do this in BOL.

    Thanks

    CSDunn

  • You can't, sorta. You can select from it using openrowset. A hack, but sometimes good enough.

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

  • cdun,

    What is it that the sp is supposed to do? If you are using it to return a flag stating whether or not a record is approved can you put the code in a user-defined function and then call that from the view??

    Good Luck

    AJ Ahrens

    webmaster@kritter.net



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Another option would be to have the stored procedure run the view using a SELECT statement. This wouldn't work if you used an updateable view though.

    Alternatively if you wish to validate data, or run a routine on insert,update or delete try using a trigger.

  • If your view just returns a recordset, why not just replace the view with a SP?

    Tim

  • I think the main issue here may be the way you are going around getting your data out.

    There may be a better way of achieving what you want. Can you post more details of what you want out?

  • quote:


    Can you post more details of what you want out?


    I have a fix for now, but I do want to explore some alternatives for doing this. When I have an opportunity, I'll post again with further details.

    Thanks for your help!

    CSDunn

Viewing 7 posts - 1 through 6 (of 6 total)

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