Skip to content

Instantly share code, notes, and snippets.

@phaniav
Created August 23, 2019 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phaniav/fc83ce856ad6df017d0d86762fc0e704 to your computer and use it in GitHub Desktop.
Save phaniav/fc83ce856ad6df017d0d86762fc0e704 to your computer and use it in GitHub Desktop.
Gist to create view in Sitecore database for querying sitecore items by path
--Returns all descendants of the /sitecore/template item
SELECT *
FROM ItemsPath
WHERE ItemPath LIKE '/sitecore/templates%'
--Returns all rows in the WorkflowHistory table for all
--descendants of the news item (/sitecore/content/Home/News)
SELECT WorkflowHistory.*
FROM WorkflowHistory
JOIN dbo.ItemsPath ON ItemsPath.ID = WorkflowHistory.ItemID
WHERE ItemPath LIKE '/sitecore/content/Home/News%'
CREATE VIEW [dbo].[ItemsPath]
AS
WITH ItemsTable (ItemPath, ID, Name, TemplateID, MasterID, ParentID, Created, Updated)
AS
(
SELECT CAST('/' + base.Name AS nvarchar(MAX)) as ItemPath,
base.ID, base.Name, base.TemplateID, base.MasterID, base.ParentID, base.Created, base.Updated
FROM Items as base
WHERE base.ID = '11111111-1111-1111-1111-111111111111'
UNION ALL
SELECT CAST(ItemPath + '/' + child.Name AS nvarchar(MAX)),
child.ID, child.Name, child.TemplateID, child.MasterID, child.ParentID, child.Created, child.Updated
FROM ItemsTable as parent
INNER JOIN Items as child
ON child.ParentID = parent.ID
)
SELECT ItemPath, ID, Name, TemplateID, MasterID, ParentID, Created, Updated
FROM ItemsTable
GO
@phaniav
Copy link
Author

phaniav commented Aug 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment