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)
 Comparing Record Values

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2007-03-01 : 10:54:17
I have a set of data in Table1 and I bring all new data into it weekly (all records) from another party. My challenge is that I need to find out which records have changed from week to week. I was thinking of just importing the new weekly data into a separate table (Table2) and compare the values. Could anyone point me in the right direction? Thanks


Table1
ID
RatingA
RatingB
RatingC

Table2
ID
RatingA
RatingB
RatingC

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-01 : 10:57:03
[code]
select *
from Table1 t1 inner join Table2 t2
on t1.ID = t2.ID
where t1.RatingA <> t2.RatingA
or t1.RatingB <> t2.RatingB
or t1.RatingC <> t2.RatingC
[/code]


KH

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-03-01 : 10:57:15
select *
from Table1 t1
join Table2 t2
on t1.ID = t2.ID
where t1.RatingA <> t2.RatingA
or t1.RatingB <> t2.RatingB
or t1.RatingC <> t2.RatingC

do you want records that are new or deleted? Do you have nulls?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-01 : 11:01:48
use FULL OUTER JOIN instead of INNER JOIN if you have new records and would like to identify which records is missing from which table.


KH

Go to Top of Page
   

- Advertisement -