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.
Author |
Topic |
Tawnos
Starting Member
3 Posts |
Posted - 2010-09-21 : 12:35:04
|
Hello all,I would like to know if there is a way to compare records against each other and determine what is the difference without the having to check one field, then if same check another, then if same check another, etc..Is there a stock SQL 2000 function/sp for this or am I asking for too much?I searched through the forums a bit but could not find what I am looking for. Forgive me if it is there and I did not find it.~Brent |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-21 : 12:37:48
|
there's no direct function for that. you need to join table twice on common fields and then compare on the other columns manually. Alternately you could apply group by and do check by taking count of distinct occurance------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Tawnos
Starting Member
3 Posts |
Posted - 2010-09-21 : 12:50:23
|
Thanks for letting me know there is nothing out there to do this already.If I understand correctly then I am more comfortable with the latter of the two options you propose; my code would look something like this:SELECT field1, field2, field3, count(*)FROM myTableWHERE (blah blah blah)GROUP BY field1, field2, field3HAVING count(*) > 1Is that what you are recommending?~Brent |
|
|
Tawnos
Starting Member
3 Posts |
Posted - 2010-09-21 : 14:16:38
|
I got it figured out. The code I used is:SELECT field1, field2, field3, count(*)FROM myTableWHERE (blah blah blah)GROUP BY field1, field2, field3HAVING count(*) > 1IF @@ROWCOUNT >= 1BEGIN --Do something here because the records are "the same"ENDThanks for the guidance visakh16.~Tawnos |
|
|
|
|
|
|
|