Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 15th, 2008, 10:04 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare 2 tables in 2 different DBs

Hello. I have to compare the values from 1 table from one database and 1 table from another database in the same server. Can anyone suggest how to do this?

I do not want to use any third party tools. I need to do this programmatically - only with sql server and C# and if there is a possibility to use only sql server.

Reply With Quote
  #2 (permalink)  
Old February 15th, 2008, 10:17 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Just fully qualify the tables.

Something like this:

SELECT t1.*, t2.* from [Database1].[dbo].[table] t1
JOIN [Database2].[dbo].[table] t2 on t1.column = t2.column

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old February 15th, 2008, 10:36 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot. That was very helpfull.

Reply With Quote
  #4 (permalink)  
Old March 7th, 2008, 03:12 AM
Authorized User
 
Join Date: Jun 2007
Location: pune, Mah, India.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just fully qualify the tables.

Something like this:

SELECT t1.*, t2.* from [Database1].[dbo].[table] t1
JOIN [Database2].[dbo].[table] t2 on t1.column = t2.column


Reply With Quote
  #5 (permalink)  
Old March 7th, 2008, 08:08 AM
Authorized User
 
Join Date: Jun 2003
Location: Colombo 04, WP, Sri Lanka.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Preethi Send a message via Yahoo to Preethi
Default

It looks like you have solved the problem. If not and your tables are really big and you need to find only the different rows you can use scripts which do that.
It is completely SQL,
http://www.sqlservercentral.com/scri...laneous/30221/


G.R.Preethiviraj Kulasingham
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare two fields from different tables pallone SQL Server 2000 10 March 23rd, 2007 05:14 PM
Compare records between two tables jaaboston Access VBA 1 December 21st, 2006 05:35 AM
compare these date fields and compare and get the susanring Oracle 1 July 24th, 2006 04:58 PM
how to compare tables data ramanadyv SQL Language 0 April 10th, 2006 04:38 AM
Compare 2 tables.... Seb_soum Classic ASP Databases 2 June 4th, 2004 05:47 PM



All times are GMT -4. The time now is 07:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.