Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Compare two fields in two databases
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shabar
Starting Member

4 Posts

Posted - 09/09/2010 :  07:12:12  Show Profile  Reply with Quote
Hi

How to compare two fields in two separate SQL server databases.


Cheers

Shabar

sakets_2000
Flowing Fount of Yak Knowledge

India
1472 Posts

Posted - 09/09/2010 :  07:37:59  Show Profile  Reply with Quote
what comparison do you want to run ? sample data and output will help.
Go to Top of Page

shabar
Starting Member

4 Posts

Posted - 09/09/2010 :  15:10:39  Show Profile  Reply with Quote
quote:
Originally posted by sakets_2000

what comparison do you want to run ? sample data and output will help.



Hi

Basically I want to run one SQL script to compare two tables fields in two separate SQL sever databases.

Say I have table T1 in database DB1 and table T2 in database DB2.


Hope this make sense


Cheers

Shabar






Go to Top of Page

shabar
Starting Member

4 Posts

Posted - 09/13/2010 :  15:33:38  Show Profile  Reply with Quote
Hi

Can we implement following format to access two databases

quote:

select *
from currentDB_table cdb
, remoteDB_table@REMOTEDBLINK rdb
where cdb.field1 = rdb.field1




Cheers

Shabar
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1834 Posts

Posted - 09/13/2010 :  19:21:07  Show Profile  Reply with Quote
If the two databases are on the same SQL Server instance, you can simply use a three part name for the "remote" database:

select here.*
from MyLocalTable here
inner join MyOtherDatabase.dbo.MyOtherTable there
on here.MyColumn = there.MyColumn

If the other database is on another instance, you could define a linked server relationship to that database and then use a four part name (LinkedServerName.Dataqbase.Schema.Object) to access the remote item.

=======================================
In all life one should comfort the afflicted, but verily, also, one should afflict the comfortable, and especially when they are comfortably, contentedly, even happily wrong. -John Kenneth Galbraith, economist (1908-2006)
Go to Top of Page

shabar
Starting Member

4 Posts

Posted - 09/14/2010 :  06:14:57  Show Profile  Reply with Quote
quote:
Originally posted by Bustaz Kool

If the two databases are on the same SQL Server instance, you can simply use a three part name for the "remote" database:

select here.*
from MyLocalTable here
inner join MyOtherDatabase.dbo.MyOtherTable there
on here.MyColumn = there.MyColumn

If the other database is on another instance, you could define a linked server relationship to that database and then use a four part name (LinkedServerName.Dataqbase.Schema.Object) to access the remote item.

=======================================
In all life one should comfort the afflicted, but verily, also, one should afflict the comfortable, and especially when they are comfortably, contentedly, even happily wrong. -John Kenneth Galbraith, economist (1908-2006)




Thanks very much Bustaz Kool

It's great


Cheers

Shabar
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1834 Posts

Posted - 09/14/2010 :  17:19:25  Show Profile  Reply with Quote
If the two databases are on the same SQL Server instance, you can simply use a three part name for the "remote" database:

select here.*
from MyLocalTable here
inner join MyOtherDatabase.dbo.MyOtherTable there
on here.MyColumn = there.MyColumn

If the other database is on another instance, you could define a linked server relationship to that database and then use a four part name (LinkedServerName.Dataqbase.Schema.Object) to access the remote item.

=======================================
In all life one should comfort the afflicted, but verily, also, one should afflict the comfortable, and especially when they are comfortably, contentedly, even happily wrong. -John Kenneth Galbraith, economist (1908-2006)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000