Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looking for ways to compare

Status
Not open for further replies.

tobermory20

Programmer
Dec 7, 2007
20
US
Hello,

I am struggling with trying to compare two different database tables in different database. in theory it seems managable, but I can seem to make it work. where is what I did in Access but need to translate for MS SQL Server

Code:
SELECT Table2.server
FROM Table2 LEFT JOIN Table1 ON Table2.server = Table1.server
GROUP BY Table2.server, Table1.server
HAVING (((Table2.server) Is Not Null) AND ((Table1.server) Is Null));

thanks in advance...
~ T
 
To access a database on another database you need to use the three part name of the object.

Code:
select *
from table1
join database2.dbo.table2 as table2 on table1.col1 = table2.col3

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
mrdenny,

Thanks for the reply. Here's my situation, I have two different Servers I am trying to access tstmd and tstsql both have a database I want to use. So do I need something like
Code:
select *
from table1
join [COLOR=red]server.[/color]database2.dbo.table2 as table2 on table1.col1 = table2.col3
 
not only do you need a 4 part name but you need to set up linked servers. Look up how to do that in Books on line.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top