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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure - variable DB-Name!

Status
Not open for further replies.

CW1

Programmer
Apr 11, 2000
8
DE
Hello
I have an Stored - Procedure with many Select's.
It is possible in an SELECT - statement the DB-Name variable to define?
e.g.
DELCARE @DB_Name nvarchar (50)
SET @DB_Name = 'TEST'
if exists (select * from @DB_Name.dbo.table) .....
Thank's [sig][/sig]
 
You could so something like this:

DELCARE @DB_Name nvarchar (50), @SQL nvarchar(500)
SET @DB_Name = 'TEST'
set @SQL = 'if exists (select * from ' + @DB_Name + '.dbo.table)'
exec(@SQL)

[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top