473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Passing a varible as an linked server name in openquery

Hi,
I would be glad if anybody can solve my problem.
I have query to be run which requires a linked server to be accessed.
Therefore I am using openquery. Now in the storedprocedure I pass linkserver name as variable and trying to use it in open query but it gives syntax error. If any body can suggest any other method or solution to this problem than it would be of great help

Try this query

Declare @LinkedServer varchar(50)
select * from openquery ( @LinkedServer , 'select * from master.dbo.spt_monitor')

Here instead of variable, if you pass the server name it works fine but if you pass the variable than it gives syntax error.
Feb 25 '08 #1
1 10452
deepuv04
227 Expert 100+
Hi,
I would be glad if anybody can solve my problem.
I have query to be run which requires a linked server to be accessed.
Therefore I am using openquery. Now in the storedprocedure I pass linkserver name as variable and trying to use it in open query but it gives syntax error. If any body can suggest any other method or solution to this problem than it would be of great help

Try this query

Declare @LinkedServer varchar(50)
select * from openquery ( @LinkedServer , 'select * from master.dbo.spt_monitor')

Here instead of variable, if you pass the server name it works fine but if you pass the variable than it gives syntax error.

Hi
first build a string query and then execute it..

Declare @LinkedServer varchar(50)
declare @Sql varchar(8000)
set @LinkedServer = 'abc'
set @Sql = 'select * from openquery (' + @LinkedServer + ' , ''select * from master.dbo.spt_monitor'')'

--print @Sql
Exec (@Sql)

thanks
Feb 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Sudhesh Nayak | last post by:
Hi, I have an Oracle (8.1) & a SQL Server 2000 database with Production data. There are situations when I need data from both the databases. My first choice was to link Oracle to SQL and run DTS...
5
by: NickBlooruk | last post by:
Hello, I have successfully linked a Lotus Notes server to our SQL Server database using an ODBC connection. This works fine when wanting to select records eg openquery(LOTUSNOTES2, 'select *...
3
by: douglascfast | last post by:
Anyone, Is this possible? I am connecting to a TeraData server via MS SQL 8.0 using the OpenQuery statement. I need to pass a list of ever-changing deal numbers My list of numbers are...
0
by: Bill J. | last post by:
I have to update a PostgreSQL linked server through MSSQL2K. I first configured the connection with ODBC as follows and I can do queries with no problem: EXEC sp_droplinkedsrvlogin @rmtsrvname...
0
by: Bill J. | last post by:
I have to update a PostgreSQL linked server through MSSQL2K. I first configured the connection with ODBC as follows and I can do queries with no problem: EXEC sp_droplinkedsrvlogin @rmtsrvname...
8
by: Ootyguy | last post by:
Trying to do this all day and googling for answers but found none, hope someone can help. Thanks in advance. select * into OPENROWSET('SQLOLEDB','SERVER';'uid';'pwd',##test) from LocalTable ...
2
by: Charles Wilt | last post by:
I have a IBM iSeries (aka AS-400) running v5r3 of OS/400 that I access via a linked server from SQL Server 2000. The following select works fine: select * from...
5
by: Neil | last post by:
I am getting time-out errors when I try to perform a simple delete on a linked server. The command is: Delete From MyTable Where PKID=12345 I have tried executing this command directly from...
0
by: flemmingk | last post by:
Using SQL Server 2005 Express on 23K, I am setting up a linked server using MSDASQL over ODBC (C/ODBC) to another server on out internal network. Linked server is a MBS Navision 3.7, Danish. When...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.