Advertisement
hecrus

Humans FastCreate

Oct 10th, 2020
1,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.86 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[crud_humans_fastCreate]
  2.     @filters CRUDFilterParameter READONLY,
  3.     @text nvarchar(256),
  4.     @username nvarchar(32)
  5. AS
  6. BEGIN
  7.     -- создание сущности в таблице по 1 полю @text
  8.  
  9.     -- извлечение параметров (здесь мы передаем depID - если он был задач)
  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_humans where fio = @text
  17.     if(@id>0) begin
  18.         select 'Человек с таким ФИО уже существует' Msg, 0 Result
  19.         return
  20.     end
  21.  
  22.  
  23.     -- добавление элемента в таблицу
  24.     insert into hr_humans(fio, depID)
  25.     values(@text, @filterItemID )
  26.     select 'Человек добавлен' Msg, 1 Result
  27.  
  28. END
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement