CAML语法- Query写法

CAML语法- Query写法

网上看到的关于caml语法的介绍,留作自己查看。
注:此文来源互联网,我自己仅仅加了一点自己的理解,可能以后会加一些自己写的Caml Query语法。

CAML语法-Query写法
1.Geq(>=)greater than or equal to
  The Geq element is an arithmetic operator that means "greater than or equal to." It can be used within a Where element in a view definition.
<Query>
  <Where>
    <Or>
      <IsNull>
        <FieldRef Name="Expires" />
      </IsNull>
      <Geq>
        <FieldRef Name="Expires" />
        <Value Type="DateTime">
          <Today />
        </Value>
      </Geq>
    </Or>
   </Where>
   <OrderBy>
   <FieldRef Name="Modified" Ascending="FALSE" />
  </OrderBy>
</Query>

此条语句表示的是返回 expires列为空或者 expires列的值(该列为datetime格式)大于今天的listItem,并按照modified列排序
2.Eq(=)equal to
  The Eq element is an arithmetic operator that means "equal to" and is used within the Query element.
<Query>
  <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
  </OrderBy>
  <Where>
    <Or>
      <Eq>
        <FieldRef Name="Status"></FieldRef>
        <Value Type="Text">Completed</Value>
      </Eq>
      <IsNull>
        <FieldRef Name="Status"></FieldRef>
      </IsNull>
    </Or>
  </Where>
</Query>

select * from list where status="completed" or status=="Null" order by modified;


3.Gt(>)"greater than
The Gt element is an arithmetic operator that means "greater than." This element is used similarly to Eq and Lt.
<Query>
  <Where>
    <Or>
      <IsNull>
        <FieldRef Name="Deadline" />
      </IsNull>
      <Gt>
        <FieldRef Name="Deadline" />
        <Value Type="DateTime">
          <Today />
        </Value>
      </Gt>
    </Or>
  </Where>
  <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE" />
  </OrderBy>
</Query>

select * from list where Deadline=DateTime.today() or DeadLine==null order by modified;
4.Lt(<)less than
The Lt element is an arithmetic operator that means "less than" and is used in queries in views. This element is used similarly to Eq and Gt.
<Query>
  <Where>
    <Or>
      <IsNull>
        <FieldRef Name="Deadline" />
      </IsNull>
      <Lt>
        <FieldRef Name="Deadline" />
        <Value Type="DateTime">
          <Today />
        </Value>
      </Lt>
    </Or>
  </Where>
  <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE" />
  </OrderBy>
</Query>

select * from olist where DeadLine==null or Deadline<DateTime.today() ordeyby modified;
5.Neq(!=)not equal to
The Neq element is an arithmetic operator that means "not equal to" and is used in queries.
<Query>
  <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
  </OrderBy>
  <Where>
    <Or>
      <Neq>
        <FieldRef Name="Status"></FieldRef>
        <Value Type="Text">Completed</Value>
      </Neq>
      <IsNull>
        <FieldRef Name="Status"></FieldRef>
      </IsNull>
     </Or>
   </Where>
</Query> 
select * from olist where Status!="Completed" or status==null;
协作应用程序标记语言 (CAML)---Query语法示例
1、Or,Lt,Gt,OrderBy
<Query>
<Where>
<Or>
<Lt>
<FieldRef Name="Stock"/>
<Value Type="Number">
15
</Value>
</Lt>
<Gt>
<FieldRef Name="Price"/>
<Value Type="Currency">
20.00
</Value>
</Gt>
</Or>
</Where>
<OrderBy>
<FieldRef Name="Title"/>
</OrderBy>
</Query>

select * from olist where stock<=15 or price>20 order by title
2、Eq

<Query>
<Where>
<Eq>
<FieldRef Name="ID"/>
<Value Type="Integer"><UserID/></Value>
</Eq>
</Where>
</Query>

select * from olist where ID==UserID


3、And,Eq,Lt,Neq,And嵌套
<Query>
<Where>
<And>
<Eq>
<FieldRef Name="AssignedTo"/>
<Value Type="Integer">
<UserID/>
</Value>
</Eq>
<And>
<Lt>
<FieldRef Name="DueDate"/>
<Value Type="DateTime">
<Today/>
</Value>
</Lt>
<Neq>
<FieldRef Name="Status"/>
<Value Type="Choice">Completed</Value>
</Neq>
</And>
</And>
</Where>
</Query>

<Query>
<Where>
<And>
<Eq>
<FieldRef Name="AssignedTo"/>
<Value Type="Integer">
<UserID/>
</Value>
</Eq>
<And>
<Lt>
<FieldRef Name="DueDate"/>
<Value Type="DateTime">
<Today/>
</Value>
</Lt>
<Neq>
<FieldRef Name="Status"/>
<Value Type="Choice">Completed</Value>
</Neq>
</And>
</And>
</Where>
</Query>

select * from olist where AssignedTo=UserId and

 (DueDate<DateTime.now() and  status!=completed)



7.5 下表是CAML查询的一些简单说明:

元素 说明
And 并且
BeginsWith 以某字符串开始的
Contains 包含某字符串
Eq 等于
FieldRef 一个字段的引用 (在GroupBy 中使用)
Geq 大于等于
GroupBy 分组
Gt 大于
IsNotNull 非空
IsNull 空
Leq 小于等于
Lt 小于
Neq 不等于
Now 当前时间
Or 或
OrderBy 排序
Today 今天的日期
TodayIso 今天的日期(ISO格式)
Where Where子句

  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值