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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can't reference linked server

Author  Topic 

fralo
Posting Yak Master

161 Posts

Posted - 2009-08-27 : 12:48:32
Having set up a linked server I can not reference the Server Name in this query. It's not recognized.

set @OFFNUM = (SELECT count(*) FROM Server2.EMPMAST.DBO.EMPMAST)

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-08-27 : 13:31:18
Are you sure that SERVER2 is the correct name for the linked server? What error message do you get?
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-08-27 : 14:03:56
Well, the real name is ESO-CAD. I just didn't wanna post the name on this site but I don't guess it matters. I checked my Linked Servers under Management Studio, and it's correct.

I hope i did everything correct when I created the linked server.
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-08-27 : 14:09:48
The query is actually

set @OFFNUM = (SELECT count(*) FROM ESO-CAD.EMPMAST.DBO.EMPMAST)

"Incorrect syntax near '-'."
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-08-27 : 14:12:33
set @OFFNUM = (SELECT count(*) FROM [ESO-CAD].EMPMAST.DBO.EMPMAST)

Jim
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-08-27 : 14:20:21
No work. [ESO-CAD].EMPMAST.DBO.EMPMAST is underlined with error Invalid object name.

Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-08-28 : 11:57:42
I've researched a little bit and have discovered the OPENQUERY rowset function. No syntax errors occur here. Hope it's correct.

set @OFFNUM = (SELECT * FROM OPENQUERY([ESO-CAD], 'SELECT COUNT(*) FROM EMPMAST.DBO.EMPMAST')
Go to Top of Page
   

- Advertisement -