GETCOLUMNVERSIONS

Used to select all versions of one or more columns from a list that has versioning enabled in SharePoint. The normal SELECT statement only retrieves the current value. This procedure can be used to retrieve the history of a column for a given item in the list.

Note! Due to the way SharePoint works, retrieving versions of a column is a significantly more expensive operation compared to normal SELECT statements. The total time will increase quickly with the number of columns added to the query. It is not recommended to use this method to iterate through large lists on regular basis.

Syntax

resultset GETCOLUMNVERSIONS(string listName, int itemId, string columnNames);

Return value

The procedure returns a list of versions where each column in columnNames is represented. The two first columns in the resultset are fixed and tell when each version was created and by who.

Column.NET Data TypeDescription
Modified System.DateTime Date of modification
Editor System.Integer User ID of the editor
Variable column 1 Variable data type Column 1
Variable column 2 Variable data type Column 2
... Variable data type ...

Example: to select all versions of column Email from list item 76 in list Customers:

CALL GETCOLUMNVERSIONS('Customers', 76, 'Email');

Example: to select all versions of column Email AND Mobile from list item 76 in list Customers:

CALL GETCOLUMNVERSIONS('Customers', 76, 'Email, Mobile');

Code examples

Select all versions

using (var command = new SharePointCommand("CALL GETCOLUMNVERSIONS('Customers', 58, 'Title, Email')", connection))
{
    using (var reader = command.ExecuteReader())
    {
        while (reader.Read())
        {
            Console.WriteLine(reader["Modified"].ToString().PadRight(20) + " : " + reader["Title"].ToString().PadRight(20) + " : " + reader["Email"].ToString());
        }
    }
}

Code result

2013-10-02 23:56:15  : Steve                : steve.h@bendsoft.com
2013-10-02 23:56:01  : Steve                : stevie@bendsoft.com
2013-09-27 00:16:02  : Steve                : steve@bendsoft.com


Skip Navigation Links.

Visa     MasterCard