Home > Archive > microsoft.public.sqlserver.server > October 2002 > sp_addlinkedserver





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sp_addlinkedserver
Wilson

2002-10-05, 9:09 pm

Hi all,

I am trying to execute this command from within a cursor, which holds a list
of server parameters with @srv_name as the server name

EXEC sp_addlinkedserver @srv_name, 'SQL Server'
SELECT * FROM @srv_name.master.dbo.sysdatabases
EXEC sp_dropserver @srv_name

First and the third line works, but the second line gives an error. If I am
using the server name instead of variable @srv_name, it works. If there is
any way I can use the vairable instead of server name because most of the
time I cannot decide in advance which wil be the server to use!

Thanks in advance
Wilson



Tibor Karaszi

2002-10-05, 9:09 pm

Wilson,

That would require dynamic SQL:

EXEC('SELECT * FROM ' + @srvname + '.pubs.dbo.authors')

--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=...ublic.sqlserver


"Wilson" <wilsontc@singnet.com.sg> wrote in message news:#7hdiciXCHA.1664@tkmsftngp09...
> Hi all,
>
> I am trying to execute this command from within a cursor, which holds a list
> of server parameters with @srv_name as the server name
>
> EXEC sp_addlinkedserver @srv_name, 'SQL Server'
> SELECT * FROM @srv_name.master.dbo.sysdatabases
> EXEC sp_dropserver @srv_name
>
> First and the third line works, but the second line gives an error. If I am
> using the server name instead of variable @srv_name, it works. If there is
> any way I can use the vairable instead of server name because most of the
> time I cannot decide in advance which wil be the server to use!
>
> Thanks in advance
> Wilson
>
>
>



Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net