SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to add IsNotNull parameter and ViewFields paramter but throwing an error. Am I inserting incorrectly or missing something to make sure this executes correctly? Seems like View is bring back all of the items in the list and just need the item I was original returning before needing to add these other parameter

                       SPQuery myquery = new SPQuery();
                        myquery.Query =
                        "<View>" +
                            "<Where>" +
                            "<And>" +
                                "<Contains>" +
                                    "<FieldRef Name='Group' />" +
                                    "<Value Type='Text'>City</Value>" +                                  
                                "</Contains>" +
                                "<Eq>" +
                                    "<FieldRef Name='System' />" +
                                    "<Value Type='Text'>" + Param.var.ToString() + "</Value>" +
                                "</Eq>" +
                                "<And>" +
                                "<IsNotNull>" +
                                    "<FieldRef Name='Email' />" +
                                "</IsNotNull>" + 
                                "</And>" +
                                "<ViewFields>" +
                                    "<FieldRef Name='Email' />" +
                                "</ViewFields>" +
                            "</And>" +
                            "</Where>" +
share|improve this question
up vote 6 down vote accepted

You don't use ViewFields inside the Where clause in a CAML query. See Query Schema and SPQuery.ViewFields Property

Also, the And around the IsNotNull node is doing nothing. The And needs two child elements to operate correctly.

share|improve this answer
gotcha! that did the trick for the ViewFields. I didn't know about the IsNotNull, I tink I can figure that one out shortly. Thanks! – nholloway4 Aug 8 '12 at 18:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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