Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE [dbo].[fm_tst-form-order_saveEditableField]
- @pk nvarchar(128), -- id for item
- @fieldCode nvarchar(64), -- form field
- @value nvarchar(max), -- field value
- @username nvarchar(256) -- current user
- AS
- BEGIN
- if(@fieldCode='f2') begin
- declare @formItemID nvarchar(128) = '', @elementID int = 0, @parentId int = 0, @ord int =0, @temp nvarchar(256)='', @index int
- set @elementID = try_cast(dbo.str_splitPart(@value, ',',1) as int)
- set @temp = dbo.str_splitPart(@value,',',2)
- set @parentId = try_cast(dbo.str_splitPart(@temp, ',',1) as int)
- set @ord = try_cast(dbo.str_splitPart(@temp, ',',2) as int)
- set @temp = cast(@parentId + @ord + @elementID as nvarchar)
- exec as_print @str = @temp
- update tst_categories
- set parentID = nullif(@parentId, 0), ord = @ord
- where id = @elementID
- declare @t table(id int, ord int)
- insert into @t
- select id, ord from tst_categories
- where isnull(parentID, 0) = @parentId and id <>@elementID
- order by ord,id
- set @index = 0
- -- обновляем порядок у предыщущих (всех у кого номер меньше)
- while (@index <@ord-1) begin
- update tst_categories
- set ord = @index+1
- where id in (select id from @t
- order by ord,id
- OFFSET @index ROWS
- FETCH NEXT 1 ROWS ONLY
- )
- set @index = @index + 1
- end
- set @index = @ord
- declare @count int = (select count(id) from tst_categories
- where isnull(parentID, 0) = @parentId )
- -- элементы после теущего
- while (@index <@count) begin
- update tst_categories
- set ord = @index+1+10000
- where id in (select id from @t
- order by ord,id
- OFFSET @index-1 ROWS
- FETCH NEXT 1 ROWS ONLY
- ) and id <>@elementID
- set @index = @index + 1
- end
- select 1 Result, '' Msg
- return
- end
- select 0 Result, 'Не найден код сущности' Msg
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement