问题
What is the caml query for a Lookup field with multi values?
So far, I am using the following without success (it just throws an error). My Lookup column is:
Lookup
-------
2;3
2
3;4
<Contains><FieldRef Name="LookupColumn"/><Value Type="LookupMulti">2</Value></Contains>
What is wrong with that query??
回答1:
Include your query inside a Where clause/tag.
<Where><Contains><FieldRef Name="LookupColumn"/><Value Type="LookupMulti">2</Value></Contains></Where>
回答2:
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Where><Eq><FieldRef Name=\"LookupColumn\" LookupId=\"TRUE\"/><Value Type=\"LookupMulti\">2</Value></Eq></Where>";
回答3:
Lookup field has ID and value associated with it something like '2|val' If you specifically want to get values based on value, then your query should look like below,
<Where><Eq><FieldRef Name="LookupColumn"/><Value Type="LookupMulti">val</Value></Eq></Where>
,
And if you want to query Lookup column based on LookupId, query should be,
<Where><Eq><FieldRef Name='MultiLookupFieldName' LookupId='TRUE'/><Value Type='LookupMulti'>" + id + "</Value></Eq></Where>
To understand the difference between
<Eq>
and <Contains>
particalurly for Lookup column, follow the URl,
https://naimmurati.wordpress.com/2013/12/03/multi-lookup-fields-in-caml-queries-eq-vs-contains/
来源:https://stackoverflow.com/questions/28208078/caml-query-for-lookup-field-with-multi-values