20

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.

Drew Gaynor
  • 8,292
  • 5
  • 40
  • 53
  • 2
    Try to search in google, there is a lot samples of caml query in sharepoint. Things that you have written doesn't look like caml query – Alexander Jun 27 '12 at 07:50
  • 2
    For some reason that I don't know, I'm sure that sharepoint has a bug, because I have two boolean columns configured by the same way (column "Returned" and column "Checked") and if I use a CAML code to query the spList by the column "Returned" it works, but when I JUST change this CAML code to query by the other column "Checked", just changing the attribute name to the column "Checked", where we set the internal field name only, the code doesn't bring me any spListitem as result, but it should return some items. very weird Column "A" (Returned) – Antonio Augusto May 10 '17 at 15:20

3 Answers3

48

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>
Ryan
  • 23,871
  • 24
  • 86
  • 132
2

This Works for me

camlQuery.ViewXml = "<View>" + "<Query>" + "<Where>" + "<Eq>" +
"<FieldRef Name='Active'/>" + " <Value Type='Boolean'>" + "1" + "</Value>" +
"</Eq>" + "</Where>" + "</Query>" + "</View>";
user692942
  • 16,398
  • 7
  • 76
  • 175
DevTard
  • 464
  • 3
  • 11
1

Use the value type Bool and it works with "true", "True" or "TRUE"

Intermernet
  • 18,604
  • 4
  • 49
  • 61