EnVisageOnline/Main-RMO/Database/Scripts/20150512/02_Update_Project_PartNum_t...

42 lines
1.6 KiB
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

USE [EnVisage]
GO
begin tran
declare @parentId uniqueidentifier
declare @prevparentId uniqueidentifier
declare @partNum int
declare @Id uniqueidentifier
declare @num int
set @num = 1
declare dupcursor cursor for select Id, [ParentProjectId] from Project
where [ParentProjectId] is not null order by [ParentProjectId], partNum
open dupcursor
fetch next from dupcursor into @Id, @parentId
while @@FETCH_STATUS = 0
begin
if @prevparentId is null or @prevparentId <> @parentId
begin
--print @prevparentId
--print @parentId
set @num = 1
set @prevparentId = @parentId
end
update Project set partnum = @num where Id = @Id
set @num = @num + 1
--print @num
fetch next from dupcursor into @Id, @parentId
end
close dupcursor;
deallocate dupcursor;
commit tran