Calling A View in a Stored Procedure

  • Dear All,

    I am trying to call a View within a Stored Procedure but I don't know if it is at all possible please?

    Thank you in advance

  • CREATE PROCEDURE P1

    AS

    SELECT * FROM VW_V1; -- VIEW

    If you are asking this, it’s possible.

  • Here is my scenario:

    We have an application which we use C#, but the way the Architecture for creating the Application is that only Views can be used to get the Data from the SQL. The trouble is, there are Data Manipulations (Delete, Updates etc...) that occur, but View would not be able to perform that. I just need to find a solution where the View could be updatable please?

  • I completely agree with Dev, but to help a bit with terminology. Normally, I would say that we call or execute functions and procedures, as they are executable objects, and we say that we query tables and views. I even say that I call an inline table valued function, even though I know that the internal workings are more similar to a view than other functions and procedures.



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • tt-615680 (11/16/2011)


    Here is my scenario:

    We have an application which we use C#, but the way the Architecture for creating the Application is that only Views can be used to get the Data from the SQL. The trouble is, there are Data Manipulations (Delete, Updates etc...) that occur, but View would not be able to perform that. I just need to find a solution where the View could be updatable please?

    Yes. It's possible.

    UPDATE Changes existing data in one or more columns in a table or view in SQL Server.

    The statement above is valid for simple views. For complex views please write, INSTEAD OF TRIGGERS (bad for performance).

  • tt-615680 (11/16/2011)


    Here is my scenario:

    We have an application which we use C#, but the way the Architecture for creating the Application is that only Views can be used to get the Data from the SQL. The trouble is, there are Data Manipulations (Delete, Updates etc...) that occur, but View would not be able to perform that. I just need to find a solution where the View could be updatable please?

    Wow, you're facing some serioys limitations here, please have a look at the remarks section of create view. There ARE ways to do this, but they may not be very effective. As a general recommendation, I would suggest you to investigate whether you can use stored procedures for creating, updating and deleting records.



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • okbangas (11/16/2011)


    tt-615680 (11/16/2011)


    Here is my scenario:

    We have an application which we use C#, but the way the Architecture for creating the Application is that only Views can be used to get the Data from the SQL. The trouble is, there are Data Manipulations (Delete, Updates etc...) that occur, but View would not be able to perform that. I just need to find a solution where the View could be updatable please?

    Wow, you're facing some serioys limitations here, please have a look at the remarks section of create view. There ARE ways to do this, but they may not be very effective. As a general recommendation, I would suggest you to investigate whether you can use stored procedures for creating, updating and deleting records.

    @ole: If I am correct it's Entity Framework Model where the application class should match to DB objects (tables / views). I am not a huge fan of this architecture but from Front End Developer's point-of-view it's very easy to understand & develop.

  • I too fear it is Entity Framework. From a database perspective, I simply hate it. I really really hate it when i see a solution sending some 4000 single inserts or updates, instead of doing it in a single statement.



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

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

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