Frist hint:
Try to replace this part of query:
SELECT p.IPersonID, p.sFirstName, p.sLastName, p.sLoginName, p.sEmail, REPLACE(o.sOrgPath, '>', '> ') AS sOrgPath,p.INodeID, p.sPersonality, fAccountType = CASE p.fAccountType WHEN 'S' THEN 'Full Access' ELSE 'Regular' END, fRights = CASE p.fRights WHEN 'A' THEN 'Administer' WHEN 'W' THEN 'Write'WHEN 'R' THEN 'Read' END
with:
SELECT p.IPersonID, p.sFirstName, p.sLastName, p.sLoginName, p.sEmail, REPLACE(o.sOrgPath, '>', '> ') AS sOrgPath, p.INodeID, p.sPersonality,
CASE WHEN p.fAccountType='S' THEN 'Full Access'
ELSE 'Regular' END AS fAccountType,
CASE WHEN p.fRights='A' THEN 'Administer'
WHEN p.fRights='W' THEN 'Write'
WHEN p.fRights='R' THEN 'Read'
END AS fRights
Second hint:
Remove
WITH[
^] near
(nolock)
statement.
Quote:
The following table hints are allowed with and without the WITH keyword: NOLOCK, READUNCOMMITTED, UPDLOCK, REPEATABLEREAD, SERIALIZABLE, READCOMMITTED, FASTFIRSTROW, TABLOCK, TABLOCKX, PAGLOCK, ROWLOCK, NOWAIT, READPAST, XLOCK, and NOEXPAND. When these table hints are specified without the WITH keyword, the hints should be specified alone. For example:
FROM t (TABLOCK)
I hope it helps ;)