How would I call a Stored Procedure that returns data in a View? Is this even possible?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- How to truncate seconds in TSQL?
- Code for inserting data into SQL Server database u
- Delete Every Alternate Row in SQL
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
- Is recursion good in SQL Server?
This construction is not allowed in SQL Server. An inline table-valued function can perform as a parameterized view, but is still not allowed to call an SP like this.
Here's some examples of using an SP and an inline TVF interchangeably - you'll see that the TVF is more flexible (it's basically more like a view than a function), so where an inline TVF can be used, they can be more re-eusable:
If you are using Sql Server 2005 you can use table valued functions. You can call these directly and pass paramters, whilst treating them as if they were tables.
For more info check out Table-Valued User-Defined Functions
I was able to call stored procedure in a view (SQL Server 2005).
Inside stored procedure we need to set:
Note that even if your MyTableValueFunction doesn't accept any parameters, you still need to include parentheses after it, i.e.:
Without the parentheses, you'll get an "Invalid object name" error.
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:
I apologize for the confusion