hecrus

demo1 updateField

Oct 17th, 2020
280
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE PROCEDURE [dbo].[crud_tst-customers_updateField]
  2.     @itemID int,
  3.     @field nvarchar(64),
  4.     @value nvarchar(max),
  5.     @username nvarchar(64)
  6. AS
  7. BEGIN
  8. -- обновление поля таблицы
  9. -- для приведения типов используйте try_cast(@value as int), Для даты try_convert(date, @value, 104)
  10.  
  11.  
  12.  
  13. if(@field = 'name') begin
  14.     update tst_customers set name = @value where id = @itemID  
  15. end else if(@field = 'fio') begin
  16.     update tst_customers set fio = @value where id = @itemID   
  17. end else if(@field = 'vip') begin
  18.     update tst_customers set vip = try_cast(@value as bit) where id = @itemID  
  19. end else begin
  20.     select 'Невалидный код свойства' Msg, 0 Result
  21.     return
  22. end  
  23. select '' Msg, 1 Result
  24.  
  25. END
  26.  
RAW Paste Data