学习:CAML – Query Lookup Field by ID; not by Value (转)

When lookup fields are created, sharepoint stores them as
ID;#Value format in related list.

for e.g.
in list “Contacts” there is column called “Country”.
There is item in contact with value “India” assigned in Country, having item ID=10.

Now for another list “List2″ when column “Country” is stored as Lookup column named “refCountry”; and for certain data item “India” is selected from combo box, Sharepoint stores it in,

10;#India in  “List 2″ -> “refCountry” column.

When having CAML query in List2

The typical query looks like
<Query>
<Where>
<Eq>
<FieldRef Name=”RefCountry”  />
<Value Type=”Lookup”>India</Value>
</Eq>
</Where>
</Query>

The disadvantage of this way is If  list Contacts is having more than one entry(item or row) having value India for Country it will return the only first one. This may give inconsistent data for further.

To avoid this query should be base on ID not by Value.
This can be achieved thru :

<Query>
<Where>
<Eq>
<FieldRef Name=”RefCountry” LookupId=”TRUE” />
<FieldRef Name=”RefCountry” LookupId=”TRUE” />
<Value Type=”Lookup”>10</Value>

</Eq>
</Where>
</Query>

where 10 is the ID for item having country=”India”

 

Come From: http://abstractspaces.wordpress.com/2008/05/05/caml-query-lookup-field-by-id-not-by-value/

转载于:https://www.cnblogs.com/LeimOO/archive/2011/09/16/2178458.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值