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

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>";
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>";
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.

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>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.