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 |
SQLIsTheDevil
Posting Yak Master
177 Posts |
Posted - 2009-11-02 : 10:07:43
|
Hello,I have a line of code which looks something like this in a stored proc:if exists (select * from {database_name}.{schema_name}.{table_name}...In this stored proc, I'm doing work on two separate databases (database1 and database2). Recently, database2 was moved to a different server. So, I created a link from database1 which links to database2. The issue is the above query has to be changed. I know I must reference the name of the linked server, preceeding the name of the database. But, from what I understand, when you add a linked server to a database, it's not just for your particular instance. So, if my buddy is also doing development work, he will see the linked server I created, including the linked name. Is there a way i can query the name of the linked server in a stored procedure? I'd like to set it to a variable, just in case the linkservername changes in the future. Thank you! |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-02 : 12:59:43
|
Variable means always: you have to use dynamic sql.To hold the name of the linked server in a table so you can query it means NOT that your linked server is not there.So your buddy can see it.Maybe you can create and delete a linked server on demand (sp_addlinkedserver or so)...But we don't know your goal. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|
|
|