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 |
|
Nexzus
Starting Member
14 Posts |
Posted - 2009-05-28 : 19:32:48
|
| Hello,We're starting off a data migration from one Enterprise Document Management System to another. I need to find all documents in the old system that are only owned by people who are no longer here, ie there's only one entry for a document in the below ACL TableRelevant Pseudo Table StructureUsers:TEXT UsernameINT IsActive (1 = Still here, 0 = is gone.)Documents:PRIMARY KEY INT DocumentIDAccessControlList:DocumentIDUsernameSystem is SQL Server 2005 on Win2K3.Any help is appreciated.***********Edit, I should probably add that, no, there's no functionality for this in the old system. |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-05-28 : 21:20:09
|
Select * fromUsers aInner joinAccessControlList bon a.Username = b.Usernameinner Join Documents con b.DocumentID = c.DocumentIDwhere a.isactive = 0 Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
Nexzus
Starting Member
14 Posts |
Posted - 2009-05-29 : 11:44:10
|
| Thank you. That looks like it will grab any document that a disabled user has access to, though. I was needing if a document only has one ACL record associated with it, and that one ACL record has a disabled user. What I need (I believe) is the correct form of this:SELECT Document.DocumentID,COUNT(ACL.DocumentID) AS DocumentACLRecordCountFROM DocumentINNER JOIN ACL ON Document.DocumentID = ACL.DocumentIDINNER JOIN Users ON ACL.UserName = Users.UserNameGROUP BY ACL.DocumentIDHAVING DocumentACLRecordCount = 1WHEREUsers.IsActive = 0;I don't know of a way to have the result of an aggregate function as a comparison in having or where clause. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-30 : 02:58:09
|
do you mean this?SELECT Document.DocumentID,COUNT(ACL.DocumentID) AS DocumentACLRecordCountFROM DocumentINNER JOIN ACL ON Document.DocumentID = ACL.DocumentIDINNER JOIN Users ON ACL.UserName = Users.UserNameWHERE Users.IsActive = 0GROUP BY ACL.DocumentIDHAVING COUNT(ACL.DocumentID)= 1; |
 |
|
|
|
|
|
|
|