Skip to content

Instantly share code, notes, and snippets.

@benmccallum
Created January 31, 2016 23:21
Show Gist options
  • Save benmccallum/0d755ab7d066443153f0 to your computer and use it in GitHub Desktop.
Save benmccallum/0d755ab7d066443153f0 to your computer and use it in GitHub Desktop.
Find all Sitecore items under /sitecore/content with $name in a field
WITH ItemsWithFullPath (id, name, fullpath)
AS
(
SELECT ID, Name, cast(name as nvarchar(max)) as fullpath
FROM [dbo].Items
WHERE ParentID = '00000000-0000-0000-0000-000000000000'
UNION ALL
SELECT i.ID, i.Name, cast((fullpath +'/' + i.name) as nvarchar(max)) as fullpath
FROM [dbo].items i
INNER JOIN ItemsWithFullPath a on i.ParentID = a.id
)
SELECT ItemId, Value, Name, FullPath
FROM [dbo].[Fields] f
INNER JOIN ItemsWithFullPath ips ON ips.ID = f.ItemId
WHERE Value = '$name'
AND ips.fullpath like 'sitecore/content/%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment