rugbert
rugbert

Reputation: 12653

Is it possible to run a SQL Server view from a stored procedure?

I have a TON of views that are rather long and dependent/depended on other views. I also have some stored procedures that need to be run weekly and these procedures need to use some of the SQL statements in the views so instead of putting the statements in the procedures I was hoping I could just run the view.

Is that possible? I'll be running these from SQL Server 2008 btw

Upvotes: 0

Views: 73

Answers (3)

dknaack
dknaack

Reputation: 60468

Yes you can query tables and views inside your stored procedure.

Upvotes: 2

Yuck
Yuck

Reputation: 50835

A stored procedure is, in essence, nothing more than a canned ad-hoc statement. Yes, it offers many other features but the point is anything you can type in an interactive query window can also be run in a stored procedure.

Views are not restricted to being run in a stored procedure.

Upvotes: 2

TomTom
TomTom

Reputation: 62093

SQL 101:

A Select statement can be run on a table or view.

So, yes, any code that can access at able can also access a view. Given the necessary permissions.

As I said - this is beginner SQL knowledge. I will add it to my list of interiew questions for junior developers.

Upvotes: 2

Related Questions