Created
February 14, 2013 21:38
-
-
Save yetanotherchris/4956634 to your computer and use it in GitHub Desktop.
Umbraco moving multiple documents
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
--drop table #temp | |
set nocount on | |
declare @OldParentId int | |
declare @ParentId int | |
declare @Id int | |
declare @Path nvarchar(150) | |
select @OldParentId = 1139 -- Set to the existing parent node | |
select @ParentId = 2457 -- Set to the new parent node | |
-- First update the parentid column | |
update umbracoNode set parentid=@ParentId where parentId=@OldParentId | |
-- Next update all the path columns for the children. | |
SELECT id,[path] into #temp FROM [umbracoNode] where parentid=@ParentId | |
while exists(select Id from #temp) | |
begin | |
select @Id=Id,@Path=[Path] from #temp | |
select @Path = REPLACE(@Path,@OldParentId,@ParentId) | |
update umbracoNode set path=@Path where id=@Id | |
print cast(@Id as varchar)+': ' +@Path | |
delete from #temp where Id=@Id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment