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
 Eliminate Duplicate Record(s)?

Author  Topic 

buffer
Starting Member

6 Posts

Posted - 2007-06-22 : 12:19:37
Hey Again,

I've been making great progress but I've hit another road block which a newbie intern like myself can't surpass. What's worse is the fact that no one is in the office today! Maybe someone can point me in the right direction with this SQL:

SELECT
r.[requestID]
,r.[requserID]
,r.[departmentID]
,CONVERT(CHAR(8),r.[submitDate],10) AS submitDate
,CONVERT(CHAR(8),r.[dueDate],10) AS dueDate
,CONVERT(CHAR(8),r.[revisedDueDate],10) AS revisedDueDate
,r.[reqStatus]
,r.[completedDate]
,d.[departmentName]
,s.[statusName]
,u.lastName + ', ' + u.firstName AS submittedBy
,ra.userID

FROM tblUserDepartment ud
INNER JOIN tblRequest r ON ud.departmentID = r.departmentID
INNER JOIN tblDepartment d ON r.departmentID = d.departmentID
INNER JOIN tblStatus s ON r.reqStatus = s.statusID
INNER JOIN tblUser u ON r.requserID = u.userID
LEFT JOIN tblRequestAssignee ra ON r.requestID = ra.requestID
WHERE ud.userID = @userID


This works great except for one thing. In tblRequestAssignee, you have 1 primary assignee and can have several other assignees (that are not primary). This is denoted by a bit field "isPrimaryAssignee" in tblRequestAssignee. When I run the query, I see every request I want to but it duplicates requests with more than one assignee. What I'm trying to do is make only the primaryAssignee display if there is one. If there's not, then null is displayed (which is already happening).

Like I said, the query is mostly working right except for this duplicate record that displays when there's 2 assignees. Any help would once again be greatly appreciated.

buffer
Starting Member

6 Posts

Posted - 2007-06-22 : 14:15:03
Problem solved!

I was messing around with the where clause but had things wrong before. The solution to this problem is:

WHERE ud.userID = @userID AND (ra.isPrimaryAssignee = 1 OR ra.isPrimaryAssignee is null)

-buffer
Go to Top of Page
   

- Advertisement -