You are here: Re: update hierarchy « MsSQL Server « IT news, forums, messages
Re: update hierarchy

Posted by Ed Murphy on 11/02/07 02:22

danko.greiner@gmail.com wrote:

> I have structure:
>
> FolderId, FolderName, ParentFolderId, FullPath
>
> e.g.
>
> 1, First, null, First
> 2, Sec, 1, First/Sec
> .....
>
> When update happens to FolderName, i need to update all FullPaths that
> are below Folder which is changing.

Untested:

declare @FolderId int
set @FolderId = 2

declare @FolderName varchar(10)
set @FolderName = 'Zwei'

update the_table
set FolderName = @FolderName
where FolderId = @FolderId

while 1 = 1
begin

update the_table
set c.FullPath = p.FullPath + '/' + c.FolderName
from the_table c
join the_table p on c.ParentFolderId = p.FolderId
where c.FullPath <> p.FullPath + '/' + c.FolderName

if @@rowcount = 0
break

end

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация