Created
August 23, 2019 16:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source of these gists come from https://chowson.github.io/sitecore-item-paths-in-sql-queries/