Advertisement
Ruslan_Rayanov

CRUD FastCreate deps

Apr 30th, 2024
589
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE PROCEDURE [dbo].[crud_deps_fastCreate]
  2.     @filters CRUDFilterParameter READONLY,
  3.     @text nvarchar(256),
  4.     @username nvarchar(32)
  5. AS
  6. BEGIN
  7.     -- создание сущности в таблице по 1 полю @text
  8.  
  9.     -- извлечение параметров из URL (в случае если наша сущность зависит от родительской сущности)
  10.     --declare @filterItemID int
  11.     --select @filterItemID = try_cast(Value as int) from @filters where [Key] = 'itemID'
  12.    
  13.    
  14.     -- проверка на существование
  15.     declare @id int
  16.     select @id = id from hr_departments where code = @text or name = @text
  17.     if(@id>0) begin
  18.         select 'Такой отдел уже существует' Msg, 0 Result
  19.         return
  20.     end
  21.  
  22.  
  23.     -- добавление элемента в таблицу
  24.     insert into hr_departments(name, code)
  25.     values(@text, @text)
  26.     select 'Отдел создан' Msg, 1 Result
  27.  
  28. END
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement