dbTalk Databases Forums  

select data from linked server

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss select data from linked server in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Phil Hunt
 
Posts: n/a

Default select data from linked server - 09-02-2011 , 09:58 AM






I have sqlserver 2008, called 'Server A'. It has a linked server setup. How
do I select from table in the linked server from 'Server A'. I can so it
with Use, but my select statement ref tables from both servers.

TIA

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: select data from linked server - 09-02-2011 , 01:51 PM






Phil Hunt (aaa (AT) aaa (DOT) com) writes:
Quote:
I have sqlserver 2008, called 'Server A'. It has a linked server setup.
How do I select from table in the linked server from 'Server A'. I can
so it with Use, but my select statement ref tables from both servers.
SELECT ..
FROM thelinkedserver.thatdb.dbo.thattbl a
JOIN yourlocaltbl b ON a.somekey = b.somekey


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #3  
Old   
Phil Hunt
 
Posts: n/a

Default Re: select data from linked server - 09-02-2011 , 03:06 PM



I am doing this from the Studio, what you wrote does not work. Do I need
OPENQUERY ?
That's what I found when I google

"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
Phil Hunt (aaa (AT) aaa (DOT) com) writes:
I have sqlserver 2008, called 'Server A'. It has a linked server setup.
How do I select from table in the linked server from 'Server A'. I can
so it with Use, but my select statement ref tables from both servers.

SELECT ..
FROM thelinkedserver.thatdb.dbo.thattbl a
JOIN yourlocaltbl b ON a.somekey = b.somekey


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: select data from linked server - 09-02-2011 , 04:48 PM



Phil Hunt (aaa (AT) aaa (DOT) com) writes:
Quote:
I am doing this from the Studio, what you wrote does not work. Do I need
OPENQUERY ?
That's what I found when I google

Since I just made up the table names and the query pattern, I am not
surprised that the query didn't work. Then again, you were supposed
to adapt the pattern to you query and work from there.

All I know now is that you have a query (well, at least I assume that you
have) and it "does not work". But I know how that query looks like, I don't
know what "does not work" means. Thus, I'm quite of my powers to help you,
unless you help me to help you. Please post your query, and explain why
you are not satisfied with it. If you get an error message, please include
the error message.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #5  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: select data from linked server - 09-02-2011 , 05:31 PM



On Fri, 02 Sep 2011 23:48:31 +0200, Erland Sommarskog
<esquel (AT) sommarskog (DOT) se> wrote:

Quote:
Phil Hunt (aaa (AT) aaa (DOT) com) writes:
I am doing this from the Studio, what you wrote does not work. Do I need
OPENQUERY ?
That's what I found when I google


Since I just made up the table names and the query pattern, I am not
surprised that the query didn't work. Then again, you were supposed
to adapt the pattern to you query and work from there.

All I know now is that you have a query (well, at least I assume that you
have) and it "does not work". But I know how that query looks like, I don't
know what "does not work" means. Thus, I'm quite of my powers to help you,
unless you help me to help you. Please post your query, and explain why
you are not satisfied with it. If you get an error message, please include
the error message.
OP, Erland has given a lot of people a lot of help, but he needs
information to be able to help effectively. I suggest that you read
the following guide. It explains how to ask technical questions in a
way that works:
http://www.catb.org/~esr/faqs/smart-questions.html
Following it, you might be able to solve the problem yourself, but
even if not, you will have much more data to include in your post.

Sincerely,

Gene Wirchenko

Reply With Quote
  #6  
Old   
Phil Hunt
 
Posts: n/a

Default Re: select data from linked server - 09-06-2011 , 10:26 AM



It actually worked, although my 4 part names was underlined red as invalid
object.


"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
Phil Hunt (aaa (AT) aaa (DOT) com) writes:
I am doing this from the Studio, what you wrote does not work. Do I need
OPENQUERY ?
That's what I found when I google


Since I just made up the table names and the query pattern, I am not
surprised that the query didn't work. Then again, you were supposed
to adapt the pattern to you query and work from there.

All I know now is that you have a query (well, at least I assume that you
have) and it "does not work". But I know how that query looks like, I
don't
know what "does not work" means. Thus, I'm quite of my powers to help you,
unless you help me to help you. Please post your query, and explain why
you are not satisfied with it. If you get an error message, please include
the error message.

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.