Hello,
Can you tell me how can i choose one database dinamically
to execute one script
ex:
use @.database_name
go
It's possible?
Best regardsAs you probably know, USE does not accept a variable. There might be ways to
accomplish what you
want to do, but you don't post what your scenario is...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:206de01c45933$c3ebc830$a501280a@.phx
.gbl...
> Hello,
> Can you tell me how can i choose one database dinamically
> to execute one script
> ex:
> use @.database_name
> go
> It's possible?
> Best regards|||not really. Not without Dynamic SQL concatenated at run time and executed
via sp_ExecuteSQL
Greg Jackson
PDX, Oregon|||Hi,
Use the belo sample.
DECLARE @.DBNAME VARCHAR(30)
DECLARE @.SQL NVARCHAR(4000)
SET @.DBNAME = 'TEST'
SET @.SQL = 'USE ' + @.DBNAME + ' SELECT * FROM sysobjects'
EXEC SP_EXECUTESQL @.SQL
Thanks
Hari
MCDBA
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:206de01c45933$c3ebc830$a501280a@.phx
.gbl...
> Hello,
> Can you tell me how can i choose one database dinamically
> to execute one script
> ex:
> use @.database_name
> go
> It's possible?
> Best regards
Showing posts with label scriptexuse. Show all posts
Showing posts with label scriptexuse. Show all posts
Sunday, March 11, 2012
Choose database dinamically
Hello,
Can you tell me how can i choose one database dinamically
to execute one script
ex:
use @.database_name
go
It's possible?
Best regards
As you probably know, USE does not accept a variable. There might be ways to accomplish what you
want to do, but you don't post what your scenario is...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:206de01c45933$c3ebc830$a501280a@.phx.gbl...
> Hello,
> Can you tell me how can i choose one database dinamically
> to execute one script
> ex:
> use @.database_name
> go
> It's possible?
> Best regards
|||not really. Not without Dynamic SQL concatenated at run time and executed
via sp_ExecuteSQL
Greg Jackson
PDX, Oregon
|||Hi,
Use the belo sample.
DECLARE @.DBNAME VARCHAR(30)
DECLARE @.SQL NVARCHAR(4000)
SET @.DBNAME = 'TEST'
SET @.SQL = 'USE ' + @.DBNAME + ' SELECT * FROM sysobjects'
EXEC SP_EXECUTESQL @.SQL
Thanks
Hari
MCDBA
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:206de01c45933$c3ebc830$a501280a@.phx.gbl...
> Hello,
> Can you tell me how can i choose one database dinamically
> to execute one script
> ex:
> use @.database_name
> go
> It's possible?
> Best regards
Can you tell me how can i choose one database dinamically
to execute one script
ex:
use @.database_name
go
It's possible?
Best regards
As you probably know, USE does not accept a variable. There might be ways to accomplish what you
want to do, but you don't post what your scenario is...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:206de01c45933$c3ebc830$a501280a@.phx.gbl...
> Hello,
> Can you tell me how can i choose one database dinamically
> to execute one script
> ex:
> use @.database_name
> go
> It's possible?
> Best regards
|||not really. Not without Dynamic SQL concatenated at run time and executed
via sp_ExecuteSQL
Greg Jackson
PDX, Oregon
|||Hi,
Use the belo sample.
DECLARE @.DBNAME VARCHAR(30)
DECLARE @.SQL NVARCHAR(4000)
SET @.DBNAME = 'TEST'
SET @.SQL = 'USE ' + @.DBNAME + ' SELECT * FROM sysobjects'
EXEC SP_EXECUTESQL @.SQL
Thanks
Hari
MCDBA
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:206de01c45933$c3ebc830$a501280a@.phx.gbl...
> Hello,
> Can you tell me how can i choose one database dinamically
> to execute one script
> ex:
> use @.database_name
> go
> It's possible?
> Best regards
Labels:
database,
database_namegoits,
dinamically,
dinamicallyto,
execute,
microsoft,
mysql,
oracle,
possiblebest,
scriptexuse,
server,
sql
Subscribe to:
Posts (Atom)