基本格式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <Query> <Where> <Eq> <FieldRef Name="FieldName" /> <Value Type="DataType">Value</Value> </Eq> </Where> <GroupBy> <FieldRef Name="FieldName" /> <FieldRef Name="FieldName" /> </GroupBy> <OrderBy> <FieldRef Name="FieldName" Ascending="TRUE"></FieldRef> <FieldRef Name="FieldName" Ascending="FALSE"></FieldRef> </OrderBy> </Query> |
文本、单选、数字、货币、是/否
DataType | Field |
---|---|
Text | Single line of text |
Choice | Choice field (menu to choose from) |
Number | Number field (1, 1.0, 100) |
Currency | Currency field ($, ¥, €) |
Boolean | Yes/No field (check box) 1 = Yes 0 = No |
1 2 3 4 5 6 7 8 9 | SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' /> <Value Type='DATA_TYPE'>{1}</Value> </Eq> </Where>", "FieldName", "Value") }; |
查阅项 Lookup
1 2 3 4 5 6 7 8 9 | SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' LookupId='TRUE' /> <Value Type='Lookup'>{1}</Value> </Eq> </Where>", "FieldName", "Value") }; |
用户或用户组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | //by ID SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' LookupId='TRUE' /> <Value Type='Integer'>{1}</Value> </Eq> </Where>", "FieldName", "1") }; //by Name SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' /> <Value Type='User'>{1}</Value> </Eq> </Where>", "FieldName", "The Name") }; |
时间
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' /> <Value Type='DateTime' IncludeTimeValue='FALSE'>{1}</Value> </Eq> </Where>", "FieldName", SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now)) }; //Today SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' /> <Value Type='DateTime'>[Today{1}}Day(s)]</Value> </Eq> </Where>", "FieldName", "+1") }; //Using Day SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' /> <Value Type='DateTime'>[2015-12-28{1}Day(s)]</Value> </Eq> </Where>", "FieldName", "+1") }; |
多选
1 2 3 4 5 6 7 8 9 | SPQuery query = new SPQuery { Query = string.Format(@"<Where> <Eq> <FieldRef Name='{0}' LookupId='TRUE' /> <Value Type='LookupMulti'>{1}</Value> </Eq> </Where>", "FieldName", "1") }; |
运算符
Operator | Meaning |
---|---|
Eq | = (等于) |
Neq | <> (不等于) |
Lt | < (小于) |
Gt | > (大于) |
Geq | >= (大于或等于) |
Leq | <= (小于或等于) |
Contains | 包含某字符串 |
IsNull | 为空 |
IsNotNull | 不为空 |
BeginsWith | 以某字符串开始的 |
DateRangesOverlap | 用于查询,以将定期事件中的日期与指定的 DateTime 值相比较,从而确定它们是否重叠。 |
Order/Group
Operator | Meaning |
---|---|
OrderBy | 排序. |
GroupBy | 分组. |