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 2005 Forums
 Transact-SQL (2005)
 How to compare two tables in the database?

Author  Topic 

pras2007
Posting Yak Master

216 Posts

Posted - 2009-10-19 : 06:40:45
Hello All,

I'm trying to compare two tables in my database, I'm doing so by union all the fields together. Below is the code that I used but
I'm getting a strange error message. The error message is shown below:

Msg 208, Level 16, State 1, Line 1
Invalid object name 'A'.


SELECT MIN(EDLV_NEW) as TableName,
[COL1],
[COL2],
[COL3],
[COL4],
[COL5]

FROM
(
SELECT 'EDLV__NEW' as TableName,
A.[COL1],
A.[COL2],
A.[COL3],
A.[COL4],
A.[COL5]

FROM A

UNION ALL

SELECT 'EDLV__OLD' as TableName,
B.[COL1],
B.[COL2],
B.[COL3],
B.[COL4],
B.[COL5]


FROM B

) tmp

GROUP BY
[COL1],
[COL2],
[COL3],
[COL4],
[COL5]


HAVING COUNT(*) = 1

ORDER BY EID

Does anyone know how to resolve this issue?

Please advice.

Thanks.

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2009-10-19 : 06:59:55
It seems tht you just copy/past code from jeff post http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspx,
modify it according to your tables name, possibly u don't have table with name, wht did u mentioned in your code tht is 'A' and 'B'
Go to Top of Page

Eli Kohen
Starting Member

6 Posts

Posted - 2009-10-21 : 01:11:15
Hello, if you need to compare table data in "DESING TIME", you can try Devart DataComparer for Sql Server http://www.devart.com/dbforge/sql/datacompare

Devart team. Database managment and data access solutions.
www.devart.com
Go to Top of Page
   

- Advertisement -