CAML Query with Nested OR's and AND's using SPServices - sharepoint-2010

I have used this post a reference CAML query with nested AND's and OR's for multiple fields. The difference for mine is I do not need AND's with nested OR's inside of them.
I have the nested OR's working by themselves, however I need to add in three AND conditions. I'm not quite sure how to do this with the nested OR's .
My goal is as follows with a sample code included below. Test-1 is equal to A or B or C and Test-2 is equal to D and Test-3 is equal to E and Test-4 is equal to F.
<Where>
<And>
<Or>
<Eq>
<FieldRef Name='Test-1' />
<Value Type='Text'>A</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Test-1' />
<Value Type='Text'>B</Value>
</Eq>
<Eq>
<FieldRef Name='Test-1' />
<Value Type='Text'>C</Value>
</Eq>
</Or>
</Or>
<And>
<Eq>
<FieldRef Name='Test-2' />
<Value Type='Text'>D</Value>
</Eq>
<Eq>
<FieldRef Name='Test-3' />
<Value Type='Text'>E</Value>
</Eq>
<Eq>
<FieldRef Name='Test-4' />
<Value Type='Text'>F</Value>
</Eq>
</And>
</And>
</Where>
Thanks for the help

Using U2U instead of another piece of software I was able to solve my problem by removing and moving the AND.

Related

A third column with values “dependant” on two or more other columns in an iGIS .glc-addon to shapefile?

I'm working with a protocol for aiding field data collection, the platform I'm using is the iOS version of GeometryITs iGIS app.
I've created a .glc-file with lookup tables associated to a .shp-file to structure the way my colleagues are collecting their field data, it looks like this:
<?xml version="1.0" ?>
<GISLayerConfiguration>
<!-- A textual description of this configuration -->
<!--
<description></description>
-->
<!--
A CodeList is used to specify Name-Value-Pairs to be used in database tables.
These Name-Value-Pairs are stored in 1 table, the lookup table, and then the
codes are stored in other tables. Applications can then replace the code with
the value to present to humans.
The CodeList element must have name, type and length attributes.
The name is used to create the lookup table.
The type and length represent the code, not the value. This allows
tables that are to be used with the CodeList to be validated.
A value element represents 1 Name-Value-Pair.
The code attribute is used to reference the value in other tables.
-->
<Attribute column="Tradart" readable-name="Trädart">
<Value data-type="N" length="10">
<field-type>CodeList</field-type>
<field-param>Tradart</field-param>
<default>1</default>
<prompt></prompt>
</Value>
<Visibility>
<list>true</list>
<edit>true</edit>
</Visibility>
</Attribute>
<CodeList name="" type="" length="">
<value code=""></value>
</CodeList>
<CodeList name="Tradart" type="N" length="3">
<value code="1">Alm</value>
<value code="2">Ask</value>
<value code="3">Bok</value>
<value code="4">Ek</value>
<value code="5">Gran</value>
<value code="6">Hägg</value>
<value code="7">Lönn, parklind</value>
<value code="8">Oxel</value>
<value code="9">Rönn</value>
<value code="10">Sälg</value>
<value code="11">Tall</value>
<value code="12">Triviallöv</value>
</CodeList>
<Attribute column="Diam_cm_in" readable-name="Diameter i centimeter - intervall">
<Value data-type="N" length="10">
<field-type>CodeList</field-type>
<field-param>Diam_cm_in</field-param>
<default>1</default>
<prompt></prompt>
</Value>
<Visibility>
<list>true</list>
<edit>true</edit>
</Visibility>
</Attribute>
<CodeList name="" type="" length="">
<value code=""></value>
</CodeList>
<CodeList name="Diam_cm_in" type="N" length="3">
<value code="1">0-30 cm</value>
<value code="2">31-40 cm</value>
<value code="3">41-50 cm</value>
<value code="4">51-60 cm</value>
<value code="5">61-70 cm</value>
<value code="6">71-80 cm</value>
<value code="7">81-90 cm</value>
<value code="8">91-100 cm</value>
<value code="9">Över 101 cm</value>
</CodeList>
</GISLayerConfiguration>
Depending on the values entered in and I want to assign a value to a third column.
The command could look something like this:
IF <Attribute column="Tradart" value="1"> AND <Attribute column="Diam_cm_in"="7","8","9"> THEN <Attribute column="Results" value = "1">
Any ideas on how to make this work? I'm a bit embarrassed to admit I don't even know what language in using, and therefore not which syntax to use...
This post is actually a re-post from earlier today, when I posted on http://gis.stackexchange.com
I realized this is probably a topic more related to actual XML or SQL programming than the general GIS topic.

SharePoint CAML Query AND/OR operators

I would appreciate any help on getting my CAML query to work.
I have the following list:
| ID | Department | Status |
I am trying to get the query to return list items where ID=1, Department=Audit, and Status= "Stopped" OR "In Progress".
Can anyone please help?
Regards,
Query:
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>1</Value>
</Eq>
<And>
<Eq>
<FieldRef Name='Department' />
<Value Type='Choice'>Audit</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='Status' />
<Value Type='Choice'>In Progress</Value>
</Eq>
<Eq>
<FieldRef Name='Status' />
<Value Type='Choice'>Not Started</Value>
</Eq>
</Or>
</And>
</And>
</Where>
</Query>
Note: it is assumed that Department is a Choice field
I would recommend you to utilize the tool that will help you build your CAML Queries, for example U2U Caml Query Builder

One or more field types are not installed properly. Go to the list settings page to delete these fields SP2010

Trying to use a CAML query for the first time but getting this error. Heres my query:
"<Where>
<And>
<And>
<And>
<And>
<Eq>
<FieldRef Name='Groupx0020Name'/>
<Value Type='Text'>" + groupName + "</Value>
</Eq>
<Eq>
<FieldRef Name='Arrived'/>
<Value Type='Boolean'>False</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Plant'/>
<Value Type='Text'>" + Plant + "</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Arrivalx0020date'/>
<Value Type='Text'>" + arrivalDate + "</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Left site'/>
<Value Type='Boolean'>False</Value>" +
</Eq>
</And>
</Where>";
I used a CAML designer to generate this query but still no luck any help will be greatly appreciated.
My problem was my content for the Plant field I had it set to text but the correct syntax was 'choice' as it was a drop down list value. I hope this helps anyone else with the same problem

Converting SQL Query to XML Query for SharePoint List

I'm using SQL Reporting 3.0 and I'm trying to query a SharePoint list. Since the SharePoint list can only be in XML inside of SQL reporting, I'm trying to figure out to to convert my SQL query into an XML query. The area I'm stuck at is inside of WHERE. I'm having difficulty with IN(#). Is there a way to convert this into an XML query? Thank you for your help its greatly appreciated.
SQL Query
SELECT Hours, Date, Project, ID, Created_By,Month
FROM TimeTracking
WHERE Project IN(#Project) AND Month IN(#Month)
XML Query
<RSSharePointList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ListName>Time Tracking</ListName>
<ViewFields>
<FieldRef Name="Hours" />
<FieldRef Name="Date" />
<FieldRef Name="Project" />
<FieldRef Name="ID" />
<FieldRef Name="Created_By" />
<FieldRef Name="Month" />
</ViewFields>
<Query>
<Where>
?
</Where>
</Query>
</RSSharePointList>
Here's an example on MSDN on using FOR XML PATH to return your query as XML. You can also add a root element by using ROOT.
Please refer to te following article:
http://msdn.microsoft.com/en-us/library/bb510462.aspx

isnull and in statement in CAML

Is it possible to combine the sharepoint <In> statement with the <IsNull> statement? I only managed to get it working using an <Or> but would be great if you could place the <isNull> inside the <In> directly.
Thanks
The solution is as follows:
<Query>
<Where>
<In>
<FieldRef Name='MyLookupField' LookupId='TRUE'/>
<Values>
<Value Type='Lookup'></Value>
<Value Type='Lookup'>1</Value>
</Values>
</In>
</Where>
</Query>