CAML query for boolean column is not working

Nirushan Ferdinand Chandran picture Nirushan Ferdinand Chandran · Jun 27, 2012 · Viewed 39.6k times · Source

Hi I have a SharePoint list to be queried for my Desktop App and I want to retrieve only the Active Members but when I queried I got only the users who aren't active. What is wrong with my CAML query?

camlQuery.ViewXml = "<<"View">><Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> " + true + "</Value></Eq></Where></Query></View>"";

I tried the following as well

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> true</Value></Eq></Where></Query></View>";

and

camlQuery.ViewXml = "<Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> true</Value></Eq></Where></Query>";

Please help as I'm new to CAML.

Answer

Ryan picture Ryan · Jun 27, 2012

Save yourself some grief and use a tool to help build up CAML queries such as U2U's Caml Query Builder.

You need to use 1 and 0 (not true and false) in the query, so

<Query><Where>
   <Eq><FieldRef Name="Active" /><Value Type="Boolean">1</Value></Eq>
</Where></Query>