RE: stored proc to access multiple databases
From: Alejandro Mesa (AlejandroMesa_at_discussions.microsoft.com)
Date: 01/12/05
- Next message: Brad Feaker: "RE: Problem using 'NOT IN' with varchar"
- Previous message: Aaron [SQL Server MVP]: "Re: Problem using 'NOT IN' with varchar"
- In reply to: Andy: "stored proc to access multiple databases"
- Next in thread: Mark Wilden: "Re: stored proc to access multiple databases"
- Reply: Mark Wilden: "Re: stored proc to access multiple databases"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 12 Jan 2005 10:51:02 -0800
> The problem I have is I cannot figure out how to insert a return character
> to make that work.
Not really.
Example:
use northwind
go
declare @sql varchar(8000)
set @sql = 'use [pubs] select * from dbo.authors'
exec(@sql)
AMB
"Andy" wrote:
> I will try and explain my situation the best I can. Here it goes.
>
> Due to the size of our data we have it partitioned into separate databases
> for each year. Every so often we update the view structure and want to keep
> the structure the same across all databases. I have a procedure created to
> use dynamic SQL and alter the views. The problem is when I try to go across
> databases. I would like to create one procedure that would alter all of the
> views on all of the databases. So say I run the procedure from the 2001
> database. I would like it to alter the views on the 2001 database as well as
> 2002, 2003 and 2004. I thought it be as easy as using a use (database name)
> statement, but you cannot use use statements in a procedure. So I tried
> using dynamic SQL. Then your statement needs to be
> use database name
> go
>
> The problem I have is I cannot figure out how to insert a return character
> to make that work. If anybody can offer suggestions I would really
> appreciate it.
> Thanks!!!!
- Next message: Brad Feaker: "RE: Problem using 'NOT IN' with varchar"
- Previous message: Aaron [SQL Server MVP]: "Re: Problem using 'NOT IN' with varchar"
- In reply to: Andy: "stored proc to access multiple databases"
- Next in thread: Mark Wilden: "Re: stored proc to access multiple databases"
- Reply: Mark Wilden: "Re: stored proc to access multiple databases"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|