Check for null values in CAML query

By Vijai Anand Dec 19, 2012
In this blog you will see how to check the null values in CAML query.

I have a custom list named "Custom" which has the following columns.

1.) Title
2.) Test

I need to use CAML query and get only the items which has null values in "Test" column.

Code snippet:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

using System.Data;

using System.Globalization;


namespace ISNULL


    class Program


        static void Main(string[] args)


            using (SPSite site = new SPSite("http://serverName/sites/Vijai"))


                using (SPWeb web = site.OpenWeb())


                    SPList list = web.Lists.TryGetList("Custom");

                    SPQuery query = new SPQuery();

                    query.Query = "<Where><IsNull><FieldRef Name='Test' /></IsNull></Where>";

                    SPListItemCollection itemColl = list.GetItems(query);

                    foreach (SPListItem item in itemColl)











Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, SharePoint 2010, Silv... Read more