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 2000 Forums
 Transact-SQL (2000)
 Eliminating Duplicate Data

Author  Topic 

Gary Costigan
Yak Posting Veteran

95 Posts

Posted - 2005-07-13 : 12:05:36
I have received a file that I need to load into a table that contains duplicate sets of data with the HOURS value in a "Plus and Minus" format. The reason for this is if an employee is originally code a paycode and then the paycode is changed we are now deducting the hours.

Here is an example of the data.

EMPID COSTCENTER PAYDATE PAYCODE HOURS
001306 0435/4510 07/01/2001 UA 8.0
001306 0435/4510 07/01/2001 UA -8.0

When I load the data is there anyway of indentifying these two lines as duplicates and not load them?

As always thanks in advance.

GC

tinkerman
Starting Member

13 Posts

Posted - 2005-07-13 : 13:57:42
SELECT EMPID, COSTCENTER, PAYDATE, PAYCODE, SUM(HOURS)
FROM Data
GROUP BY EMPID, COSTCENTER, PAYDATE, PAYCODE
Go to Top of Page

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2005-07-13 : 15:32:57
SELECT A.EMPID, A.COSTCENTER, A.PAYDATE, A.PAYCODE, A.HOURS
FROM YourTable AS A
JOIN
(SELECT EMPID, COSTCENTER, PAYDATE, PAYCODE
FROM YourTable
GROUP BY EMPID, COSTCENTER, PAYDATE, PAYCODE
HAVING COUNT(*) = 1) AS B
ON A.EMPID = B.EMPID AND A.COSTCENTER = B.COSTCENTER AND A.PAYDATE = B.PAYDATE AND A.PAYCODE = B.PAYCODE
Go to Top of Page
   

- Advertisement -