The thing with CAML to me, is that it is not well defined. There are potholes everywhere, and sketchy information online, even from MSDN.
I was trying to lookup a SPUser I have selected in another list. In the source list, I have a field with a lookup for user named Employee, the rest is like a Contancts list.
So normally, I break open U2U's CAML Query builder, build a query... but this is no good, the standard uses the display name?
Here is the query that was generated:
<Where>
<Eq>
<FieldRef Name='Employee' />
<Value Type='User'>Daniel Keeling</Value>
</Eq>
</Where>
That looks fine right? Well for small environments sure, but what if there were two Daniel Keelings! (There is actually a music producer from England who shares my name :) )
Anyways, so there has to be another way to lookup the user, I mean I have the SPUser in code, I can get anything, email, ID, etc.
Well it just so happens that you CAN use ID.
Amend the Query to look like so:
<Where>
<Eq>
<FieldRef Name='Employee' LookupId='TRUE' />
<Value Type='User'>UserId</Value>
</Eq>
</Where>
Then just wrap it into a SPQuery, replacing UserId with the SPUser.ID (int)... and now you are unique.