hecrus

Tree CreateItem

Oct 24th, 2020
890
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE PROCEDURE [dbo].[tree_tst-catalog_createItem]
  2.     @parameters DictionaryParameter READONLY,
  3.     @parentID nvarchar(128),
  4.     @name nvarchar(128),
  5.     @itemID nvarchar(128),
  6.     @username nvarchar(32)
  7. AS
  8. BEGIN
  9.     declare @catParentID int
  10.     set @catParentID = try_cast(@parentID as int)
  11.     if(@catParentID=0) set @catParentID=null
  12.  
  13.     declare @categoryID int
  14.     insert into tst_categories(name, parentID, ord)
  15.     values (@name, @catParentID, isnull((select max(ord) + 10 from tst_categories where parentID = @catParentID),10))
  16.     set @categoryID = scope_identity()
  17.    
  18.     declare @l int = 1, @curParentID int
  19.     set @curParentID = @catParentID
  20.     while isnull(@curParentID,0)<>0
  21.     begin
  22.         set @l = @l + 1
  23.         select @curParentID = parentID from tst_categories where id = @curParentID
  24.     end
  25.     update tst_categories set level = @l where id = @categoryID
  26.    
  27.     declare @code nvarchar(max), @url nvarchar(max)
  28.    
  29.     set @code = dbo.tst_getCategoryCode(@categoryID)
  30.     update tst_categories set code = @code where id = @categoryID
  31.    
  32.     set @url = dbo.tst_getCategoryURL(@categoryID)
  33.     update tst_categories set url = @url where id = @categoryID    
  34.    
  35.     -- SELECT 1
  36.     Select 1 Result, '' Msg, @categoryID [NewID]
  37. END
RAW Paste Data