2013-05-22 120 views
2

以下CAML查詢不適用於我..我不太瞭解sharepoint平臺。我正在使用SP 2007,並嘗試使用IN運算符來查找字段。多條件下的CAML IN運算符和AND運算符

"<Where>" 
           + "<And>" 
           + "<And>" 
           + "<In>" 
           + "<FieldRef Name='Role'/>" 
           + "<Values>" 
           + "<Value Type = 'Text'>A</Value>" 
           + "<Value Type = 'Text'>B</Value>" 
           + "</Values>" 
           + "</In>" 
           + "<Leq>" 
           + "<FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>" 
           + "</Leq>" 
           + "</And>" 
           + "<Includes>" 
           + "<FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>" 
           + "</Includes>" 
           + "</And>" 
           + "</Where>"; 

上面的查詢不返回任何東西,但我有我的列表中對上述組合值。

如果我稍微修改查詢,如跟隨使用IN的W/O然後它工作正常。

"<Where>" 
           + "<And>" 
           + "<And>" 
           + "<Eq>" 
           + "<FieldRef Name='Role'/>" 
           //+ "<Values>" 
           + "<Value Type = 'Text'>A</Value>" 
           //+ "<Value Type = 'Text'>B</Value>" 
           //+ "</Values>" 
           + "</Eq>" 
           + "<Leq>" 
           + "<FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>" 
           + "</Leq>" 
           + "</And>" 
           + "<Includes>" 
           + "<FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>" 
           + "</Includes>" 
           + "</And>" 
           + "</Where>"; 

(請不要建議我使用CAML查詢生成因爲我不能在我的DEV機器上安裝任何東西。而且我還沒有在我的本地安裝SP WSS :))

回答

6

中CAML的運營商是在Sharepoint 2010中引入的。您無法在Sharepoint 2007中使用它。要獲得相同的結果,您必須將其作爲OR編寫。

<Or> 
<Eq> 
    <FieldRef Name='Role' /> 
    <Value Type='Text'>A</Value> 
</Eq> 
<Eq> 
    <FieldRef Name='Role' /> 
    <Value Type='Text'>B</Value> 
</Eq> 
</Or> 
+0

謝謝Onots ...我遇到了以下鏈接,他也像你一樣表達了:)http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/64e329f1-9f11-4c80-a2c3 -3062435c442a – Magesh

2

如果有人還在用2007年的SharePoint,並希望在多個條件操作使用,你可以做到這一點像下面,在這裏我用「OR」操盤手「IN」

string lCAMLQuery =    "<Where>" 
             + "<And>" 
             + "<And>" 
              + "<Leq>" 
               + "<FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value>" 
              + "</Leq>" 
             + "<Or>" 
              + "<Eq>" 
               + "<FieldRef Name='Role' />" 
               + "<Value Type='Text'>A</Value>" 
              + "</Eq>" 
              + "<Eq>" 
               + "<FieldRef Name='Role' />" 
               + "<Value Type='Text'>D</Value>" 
              + "</Eq>" 
             + "</Or>" 
             + "</And>" 
              + "<Includes>" 
               + "<FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value>" 
              + "</Includes>" 
             + "</And>" 
            + "</Where>"; 
1
string lCAMLQuery = @"<Where> 
        <And> 
        <And> 
         <Leq> 
          <FieldRef Name='Enddate'/><Value Type = 'DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(Dt) + " </Value> 
         </Leq> 
        <Or> 
         <Eq> 
          <FieldRef Name='Role' /> 
          <Value Type='Text'>A</Value> 
         </Eq> 
         <Eq> 
          <FieldRef Name='Role' /> 
          <Value Type='Text'>D</Value> 
         </Eq> 
        </Or> 
        </And> 
         <Includes> 
          <FieldRef Name='Menu'/><Value Type='Text'>Benefits</Value> 
         </Includes> 
        </And>";