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
 General SQL Server Forums
 New to SQL Server Programming
 Help writing a stored procedure

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-09-15 : 10:04:41
I have two tables

Table 1 = Weekly Diaries

Table 2 = New Diary

How do I write a stored procedure to get the duplicates out of both tables?

Both tables have the field name HUN where I want to do my search on.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-15 : 10:13:05
Duplicates as multiple occurencies in each table?
Duplicates as in a match between tables?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-09-15 : 10:13:15
select hun,[dups] = count(*)
from Table1
group by hun
having count(*) > 1

Jim
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-09-15 : 10:26:56
Thank you both for your reply. I want the matching duplicates to go into another table. How would I add that to this statement?

select hun,[dups] = count(*)
from Table1
group by hun
having count(*) > 1

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-15 : 10:28:48
SELECT t1.Col1, COUNT(*)
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t2.Col1 = t1.Col1
GROUP BY t1.Col1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2008-09-15 : 11:00:52
Thanks!
Go to Top of Page
   

- Advertisement -