hecrus

CRUD FastCreate

Oct 10th, 2020
642
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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×