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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 linked server query

Author  Topic 

ericwebb
Starting Member

1 Post

Posted - 2014-02-04 : 19:37:15
Hi Everyone,

Need help on using sub queries with linked openquery

Trying to query two different servers such as

select *
from linked1.test..names
where fname in (select fname from employees where active = 1)

The above will get results but will download the thousands of records and waste resources. I am trying below with openquery but cannot get it to work. Can someone assist?

Select * from OpenQuery (linked1, 'Select * from test..names where in ' (select fname from employees where active = 1) ')


What is the best way to accomplish the above?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-11 : 01:35:36
[code]
select *
from linked1.test..names l
inner join employees e
on e.fname = l.fname
and e.active = 1
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -