For this below logic, how to write a CAML query? Kindly guide me.
Query Logic:
where department ='HR' And (Team='A' Or Team ='C' Or Team ='D')
Here "department" and "Team" is column name and ("HR","A","C","D") is value.
Considered that Team
and Department
columns are text column.
"<Query><Where>"+
"<And>"+
"<Or>"+
"<Or>"+
"<Eq><FieldRef Name='Team' /><Value Type='Text'>A</Value></Eq>"+
"<Eq><FieldRef Name='Team' /><Value Type='Text'>C</Value></Eq>"+
"</Or>"+
"<Eq><FieldRef Name='Team' /><Value Type='Text'>D</Value></Eq>"+
"</Or>"+
"<Eq><FieldRef Name='department' /><Value Type='Text'>HR</Value></Eq>"+
"</And>"+
"</Where></Query>"
Check my answer on how to write nested query.
You can easily create CAML queries if you use any of these s/w these are free to use and available in both install/offline packages. However, CAML query for your scenario would look like this.
Free CAML query builder: BIWUG CAML Designer for SP 2016/13/10 to O365
<Where>
<And>
<Or>
<Or>
<Eq>
<FieldRef Name='Team/>
<Value Type='Choice'>A</Value>
</Eq>
<Eq>
<FieldRef Name='Team' />
<Value Type='Choice'>B</Value>
</Eq>
</Or>
<Eq>
<FieldRef Name='Team' />
<Value Type='Choice'>C</Value>
</Eq>
</Or>
<Eq>
<FieldRef Name='Department' />
<Value Type='Choice'>HR</Value>
</Eq>
</And>
</Where>