Lookup Fields

Another post on relational data in SharePoint.

The lookup field turns out to be one hell of a powerfull tool! Suppose you want to relate two different list items or documents. For this purpose you need to use the lookup field.
This field internally stores the ID of the related item, but in the drop-down it displays whatever field you want. However, in your CAML queries you can use both values!

To query the display-value, your CAML would look like this:
<Query>
   <Where>
     <Contains>
       <FieldRef Name="Event" />
         <Value Type="Lookup">Cronos</Value>
     </Contains>
   </Where>
</Query>


To perform a query on the ID you just need to specify LookupId='true' in the FieldRef tag:

<Query>
   <Where>
     <Eq>
       <FieldRef Name="Event" LookupId="true"/>
         <Value Type="Lookup">7</Value>
     </Eq>
   </Where>
</Query>