Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to set servername, database and table at runtime?

Status
Not open for further replies.

MarkMarkov

IS-IT--Management
Mar 23, 2005
1
US
Is is possible to set the servername, database and table at runtime and then do a select using that setting? In other words, something like:

declare @r varchar
set @r = "server.databasename.dbo.table"
select * from @r
 
This is the ANSI SQL forum, not the SQL SERVER forum.


You can do that easily with Dinamyc SQL, but not with Stored Procedures in Transact-SQL (which is used by SQL Server and Sybase).

You can also do it with Oracle in PL/SQL.

But as many others have said before using dinamic tables on SP´s is not a good move. If you just need to change the database, then you can use something like.

@db = 'MyDB'

EXEC (@db + '.dbo.DeleteUserByMasterId @ID = ' + @ID)





Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top