Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AAAV
Posting Yak Master
152 Posts |
Posted - 2011-12-16 : 13:48:40
|
| exec ('select empname from [(select databasename from dbo.SQLDatabaseInstalled where databaseID='DB1').dbo.data_input_master_export') Is this possible?I have to get the employee list based on the db.Like i can configure the sQLDBInstalled to point to a db instance and then this query has to fetch it from the instance i point to.how to do it? |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
AAAV
Posting Yak Master
152 Posts |
Posted - 2011-12-16 : 13:58:50
|
| This is what i want to doi am checking if a empid is in few databases depending on which db the application is connected to(session)hence i have to first get the dbname then check if that empidis in that particular db...The db the query has to check differs. exec ('select empid from ['+ exec('select SUBSTRING(databaseconnectionstring, CHARINDEX (''='',databaseconnectionstring)+1, CHARINDEX ('';'',databaseconnectionstring)-CHARINDEX (''='',databaseconnectionstring)-1) from dbo.SQLDatabaseInstalled where databasename=''DB1''') +'].dbo.emp_master_export')it has to first exec the inner sql and find which db to prefix...db1.dbo.emp_master_exportor db2.dbo.emp_master_export and so on. |
 |
|
|
|
|
|