Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a SQL stored proc from a SQL view

I am finding that calling a stored proc in Excel is not as easy as it should be, but calling a view, or a direct table is very easy. So, how can I create a view that will call a stored proc with no params?

I know I won't be able to pass any values into the view, and I don't need or want to, Just want to wrap a stored proc in a view.

something like select exec MyStoredProc() would be great.

like image 216
Russ Avatar asked Dec 08 '08 16:12

Russ


People also ask

Can I execute a stored procedure from a view?

You can do the subqueries-to-temp table stuff in a stored procedure, but you can't call a stored procedure from a view.

Can we call a stored procedure from a view SQL?

Answers. No, but most-likely you can convert your stored procedure to a table-valued function. Then you can call the table-valued function in a view.

How do I run a stored procedure in SQL?

Using SQL Server Management Studio Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure.

Can you execute a stored procedure in the database?

A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.


2 Answers

iirc (I don't have a copy to hand) if you happen to be in T-SQL it should be possible to select * from a user defined table function (which are for most intents and purposes identical to sprocs) which returns a table variable.

like image 113
annakata Avatar answered Oct 19 '22 16:10

annakata


You should be able to put a trigger on a dummy table, and call the proc inside the trigger.

This is definitely a hack, and you would want to really lock down permissions on the table and proc.

like image 1
Guy Starbuck Avatar answered Oct 19 '22 16:10

Guy Starbuck