RE: USE @variable

RE: USE @variable

 

  

This is not good for performance, but you can use dynamic sql for your entire script.

declare @dbnum char(1), @path varchar(20), @db varchar(20), @sql
varchar(1024)
set @dbnum = 1
set @db = 'DMPVTRN' + @dbnum
set @path = 'pvtrn' + @dbnum + '.ip'
set @sql = 'use ' + @db

set @sql = sql + ' ' + -- Here goes the script to be run in the DB

select @db, @path, @sql
exec (@sql)
GO



-----Original Message-----
From: Slav_Popov [mailto:mssqldba-ezmlmshield-x42002818.[Email address protected]
Sent: Miércoles, 29 de Junio de 2005 01:45 p.m.
To: LazyDBA Discussion
Subject: USE @variable

How can I switch current database in a script?

USE @variable does not work

I tried the following and id did not work either:

declare @dbnum char(1), @path varchar(20), @db varchar(20), @sql
varchar(1024)
set @dbnum = 1
set @db = 'DMPVTRN' + @dbnum
set @path = 'pvtrn' + @dbnum + '.ip'
set @sql = 'use ' + @db
select @db, @path, @sql
exec (@sql)
GO


Thanks,
Slav.


---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY Website : http://www.LazyDBA.com To unsubscribe: http://www.lazydba.com/unsubscribe.html




MS Sql Server LazyDBA home page