Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Site Related Discussions
 Creating Views within sp's

Author  Topic 

davidpardoe
Constraint Violating Yak Guru

324 Posts

Posted - 2001-04-27 : 10:25:20
I am trying to create a view in a stored procedure but am unable to do so in anything other than the database in which the sp is stored.

I have tried the following:-

"Use @database" - @database is passed as a parameter to the sp - cannot use "use database" in an sp!

Including the database and user as identifiers in the "create view" statement - cannot use a database identifier with a view!

Running the sp from within the database I want to create the view (the sp is stored in a different database) - the view is created in the database that the sp is stored in!

I have noticed that 'nr' has put forward the view that views are redundant in SQL 2000 anyway and that the equivalent can be done with sp's. How can I do this so that I can reference the view/sp within a query?

My final alternative is to simply create the table instead of just using the view (essentially a virtual table?). The problem with this is that the view involves joining three tables each with the same number of records, keyed on an id (1-1 link) - each table has more than 3 million records and more than 100 fields!

Any thoughts?

PS. I did like the sp regarding beer - it made me chuckle on a grim rainy day in London!

   

- Advertisement -