CAML Query for lookup field with multi values

一个人想着一个人 提交于 2019-12-24 15:42:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!