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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Creating Views Using SPs

Author  Topic 

davidpardoe
Constraint Violating Yak Guru

324 Posts

Posted - 2001-05-01 : 11:23:12
I got the following response to the problem of not being able to create a view in anything other than the current database

===================================
You can only create a view in the current database......but...

Here is a way around it. Call sp_executesql from the database you want it in

I.E.

declare @SQL nvarchar(2000)

select @sql = 'create view myView AS select * from authors'

exec pubs.dbo.sp_executesql @sql
===================================

My problem now is that I want to use an sp to create the view in a database passed to the sp as a parameter. I tried dynamically building the sql that calls the sp sp_executesql, including the paramaeter in place of 'pubs' above. Problem being that when you try to execute this string the @sql variable is now undeclared!

Next try was to dynamically build the @sql parameter as well - but I have parameters in that too.

I am thinking that "global" parameters may be the way to go - ie. parameters that can be passed from one batch to another.

Any thoughts



Edited by - davidpardoe on 05/01/2001 11:38:52
   

- Advertisement -