2

I have the following 2 queries: first one is this-

1)

@"<Where>
  <Eq>
   <FieldRef Name='ReportsTo' />
   <Value Type='Text'>" + reportsTo + @"</Value>
  </Eq>
</Where>"

And the second one is this:

2)

@"<Where>
   <Eq>
    <FieldRef Name='Team' />
    <Value Type='Text'>"+ selected+ @"</Value>
   </Eq>
 </Where>";

How Can I merge these two queries in just one Query.

Please help me

4 Answers 4

8

If you want to compare with both conditions than use AND:

@"<Where>
 <And>
  <Eq>
   <FieldRef Name='ReportsTo' />
   <Value Type='Text'>" + reportsTo + @"</Value>
  </Eq>
  <Eq>
    <FieldRef Name='Team' />
    <Value Type='Text'>"+ selected+ @"</Value>
   </Eq>
 </And>
</Where>";

If you want to compare with one of the conditions in query than use OR:

@"<Where>
 <Or>
  <Eq>
   <FieldRef Name='ReportsTo' />
   <Value Type='Text'>" + reportsTo + @"</Value>
  </Eq>
  <Eq>
    <FieldRef Name='Team' />
    <Value Type='Text'>"+ selected+ @"</Value>
   </Eq>
 </Or>
</Where>";
0
1

Wrap your conditions in <And>...</And> inside <Where>

Reference: https://msdn.microsoft.com/en-us/library/office/ms196939.aspx

@"<Where>
    <And>
        <Eq>
            <FieldRef Name='ReportsTo' />
            <Value Type='Text'>" + reportsTo + @"</Value>
        </Eq>
        <Eq>
            <FieldRef Name='Team' />
            <Value Type='Text'>"+ selected+ @"</Value>
        </Eq>
    </And>
</Where>";
0
1

You can use like this:

@"<Where>
<And>
  <Eq>
   <FieldRef Name='ReportsTo' />
   <Value Type='Text'>" + reportsTo + @"</Value>
  </Eq>
  <Eq>
    <FieldRef Name='Team' />
    <Value Type='Text'>"+ selected+ @"</Value>
   </Eq>
</And>
</Where>"

NOTE: You can also use <Or> tag also for or condition instead of <And> tag.

0
1
@"<Where>
    <And>
      <Eq><FieldRef Name='ReportsTo' /><Value Type='Text'>" + reportsTo + @"</Value></Eq>
      <Eq><FieldRef Name='Team' /><Value Type='Text'>"+ selected+ @"</Value></Eq>
   </And>
</Where>"
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.