Copied to clipboard

Flag this post as spam?

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


  • Matt Taylor 873 posts 2086 karma points
    May 22, 2017 @ 14:03
    Matt Taylor
    0

    How to query the cmsContentXml table in SQL?

    I have a requirement to generate a list of members along with some details and the created date.

    I think I want to generate an SQL query that will do this.

    The data I need is all in the cmsContentXml table's [xml] field stored as ntext which makes it difficult to query.

    Normally the standard query I'd run would be:

    SELECT nodeName, createDate FROM cmsContentXml WHERE nodeType='1085'

    But how can I do this with the data in the ntext field?

    Kind regards,

    Matt

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 22, 2017 @ 21:33
    Alex Skrypnyk
    0

    Hi Matt

    I would recommend you to get all data from Examine index. Query database directly isn't the best way to work with Umbraco tasks.

    Look please how to do it with Examine - https://our.umbraco.org/documentation/reference/searching/examine/

    Examine is unbelievable fast and you can add to index any custom data.

    Thanks

    Alex

  • Matt Taylor 873 posts 2086 karma points
    May 23, 2017 @ 09:46
    Matt Taylor
    101

    Thanks Alex,

    It had not occurred to me to use Examine.

    In this case I'm putting together the query for someone that is familiar with SQL but not Umbraco or Luke so I'm trying to keep it simple for them.

    I've come up with the following which produces what I wanted.

    select
    CAST([xml] as XML) as xmldata
    Into #xmlmembers
    from [abc_umbraco].[dbo].[cmsContentXml]
    where xml like '%nodeType="1085"%'
    
    select
    xmldata.value('(/node/@id)[1]','nvarchar(max)') as [id],
    xmldata.value('(/node/@createDate)[1]','nvarchar(max)') as createDate,
    xmldata.value('(/node/@nodeName)[1]','nvarchar(max)') as [name],
    xmldata.value('(/node/@loginName)[1]','nvarchar(max)') as [loginName],
    xmldata.value('(/node/@email)[1]','nvarchar(max)') as [email],
    xmldata.value('(/node/company)[1]','nvarchar(max)') as [company]
    from #xmlmembers
    
    drop table #xmlmembers
    

    Thanks, Matt

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 23, 2017 @ 14:29
    Alex Skrypnyk
    0

    Hi Matt

    Thank you for sharing solution!

    Have a great day.

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft