Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brendan Rice 538 posts 1100 karma points
    Jan 05, 2012 @ 22:23
    Brendan Rice
    0

    TSQL to get a nod eby id with related properties

    Is there any way in TSQL to get a node with its properties as a table?

    What I really need to do is find any nodes with a particular property set.

    Any help would be really appreciated.

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Jan 06, 2012 @ 09:41
    Sebastiaan Janssen
    1

    Rszor?

     

    @{
        //Start at the root node
        var nodes = traverse(Model.AncestorOrSelf());
    }
    
    <h1>Nodes with bodyText property that has a value</h1>
    @foreach(var node in nodes)
    {
        @node.Name<br/>
    }
    
    
    @functions {
        public List<dynamic> traverse(dynamic startNode)
        {
            var nodes = new List<dynamic>();
            foreach (var item in startNode.Children)
            {
                if (item.HasProperty("bodyText") && item.HasValue("bodyText"))
                {
                    nodes.Add(item);
                }
    
                //as this is recursive, it'll go through all of the content
                traverse(item);
            }
    
            return nodes;
        }
    }

     

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 06, 2012 @ 12:19
    Lee Kelleher
    1

    Hi Brendan,

    It would be difficult to get all the nodes and property data into a single table/view. (Guessing you mean like a pivot'd view with all properties as columns?)

    When you say that you want to find all the nodes with a particular property set - do you mean nodes that have specific properties, or those with a specific value?

    I've used the following T-SQL snippet for getting a list of node ids for properties with a specific value.

    DECLARE @search NVARCHAR(50);
    SET @search = 'green';
    
    SELECT
        n.id,
        n.path
    FROM
        cmsPropertyData AS pd
        INNER JOIN umbracoNode AS n ON n.id = pd.contentNodeId
        INNER JOIN cmsDocument AS d ON n.id = d.nodeId
    WHERE
        d.newest = 1 AND d.versionId = pd.versionId
        AND
        (
            pd.dataNvarchar LIKE ('%' + @search + '%')
            OR
            pd.dataNtext LIKE ('%' + @search + '%')
        )
    ;

    Sure it can be adapted to suit your needs.

    Cheers, Lee.

  • Brendan Rice 538 posts 1100 karma points
    Jan 07, 2012 @ 00:13
    Brendan Rice
    0

    Thanks guys Lee that is more than what I need, really appreciate the help. Razor is good Seb but I need TSQL this time.

    Thanks again.

  • Anton 135 posts 186 karma points
    Feb 21, 2012 @ 13:49
    Anton
    0

    How do a pivot'd view with all properties as columns?

Please Sign in or register to post replies

Write your reply to:

Draft