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 |
|
Srain
Starting Member
23 Posts |
Posted - 2009-01-31 : 23:01:04
|
| Hii have a simple select query which is hardcoded many a times in a SP as the SP fetching data from multiple servers.select * from [server1].[database1].[dbo].[table1]Now the requirement is - To put the [server1].[database1].[dbo].[table1] in a variable & use the variable in the above select query. Please suggest. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-31 : 23:16:35
|
Remember Your Server Should be Linked to Other Server or instance . Also It is not recommendable as Tara said:DECLARE @LINKEDSERVER VARCHAR(300)SET @LINKEDSERVER = 'SERVERNAME.DATABASENAME.SCHEMA.TABLENAME'EXEC('SELECT * FROM ' + @LINKEDSERVER) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-01 : 01:10:23
|
| or else you need to use OPENROWSET along with dynamic sql. |
 |
|
|
|
|
|