Original Address:Http://www.stum.de/2008/02/06/querying-the-person-or-group-field-using-spquery/Querying the "person or group" field Using SPQuery (Update)
One of the weak points of Sharepoint is documentation. If you want to query a ' person or Group ' field, the documentation on MSDN is a bit sparse.
Here's how to query a person:
<where>
<eq>
<fieldref name= "Personfieldname"/>
<value type= "User" >user Display name</value>
</eq>
</where>
Replace Personfieldname with the internal Name of the Field.
The important things Here:value Type is "User", and the String to search for is the Display Name. So if you had a user called "John Doe" whose login is "Mydomain\jdoe" and you had to search for "John Doe" and not for "Mydoma In\jdoe ".
There is a obvious drawback to this:what if you have both users called John Doe?
I was quite disappointed, the person field does not the store the LoginName by default and can therefore is not queried fo R it.
There is and workarounds. The first one:go to the the field in the list, and at the bottom you can change "Show field" to "account".
This has the advantage so you can use the ' domain\username ' Syntax now. The Drawback:the field looks bad at the list as it does now show the Login, not the Display Name with the neat presence s Tatus.
The second workaround:use the undocumented LookupId property and search for the numeric ID:
<where>
<eq>
<fieldref name= "Personfieldname" lookupid= "TRUE"/>
<value type= "int" >UserID</value>
</eq>
</where>
The UserID is not the ' domain\username ', but the numeric internal ID (spuser.id). As I use the workflow, I can easily access this through WorkflowProperties.OriginatorUser.ID, which is good enough f or me.
Update: The second code example is incorrect, I fixed it now.
[for future reference] use SPQuery to query the "person or Group" field