如何将存储过程转换为视图

在良 方 0 Reputation points
2023-03-23T02:29:07.3366667+00:00

将现有的存储过程转换为视图

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,707 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CosmogHong-MSFT 22,941 Reputation points Microsoft Vendor
    2023-03-23T02:50:37.43+00:00

    Hi @在良 方

    View is a virtual table. While stored procedure is a collection of sql statements and most time include parameters.

    When you define a view, you can include only Select statement. See: CREATE VIEW (Transact-SQL).

    In my opinion, there is no meaning in converting stored procedure to view.

    How do I convert a stored procedure with parameters into a view

    Maybe sometimes you can transform procedure code into a single Select in unobvious ways, but this is always very case-specific. For better support, you'd better post your stored procedure code.

    Consider that you have parameters within the SP, I don't think it's possible to convert this SP to a view since we can't declare parameters when defining a view.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.