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
 Comparing Local and Linked Server Query Help

Author  Topic 

mflammia
Starting Member

44 Posts

Posted - 2008-07-31 : 18:11:46
Trying to write a query that will compare the contents of a Linked server table with a local one and return only the results of those that match.

I have tried to gleam what I can below from this link http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspx but get the following error:

Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'FROM'.
Msg 156, Level 15, State 1, Line 15
Incorrect syntax near the keyword 'FROM'.

SELECT MIN(TableName) as TableName, ID, COL1

FROM

(

select * from openquery (TTDNY1,'Select ID, listingTitle from listings') as TableName, A.ID, A.COL1

FROM A

UNION ALL

Select ID, _name from realessex.dbo._DATA as TableName, A.ID, B.COL1

FROM B

) tmp

GROUP BY COL1

HAVING COUNT(*) = 2

Order by ID



Not sure what is happening. Your help is greatfully received as usual.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-07-31 : 23:24:57
What are 'from a' and 'from b' for?
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2008-08-01 : 03:09:43
--you are not using linked server here. openquery considers any database as homogenious
use the table name before alias names

Arnav
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-08-02 : 14:44:30
You can access linked server with openquery.
Go to Top of Page
   

- Advertisement -