Advertisement
hecrus

MySQL UpdateField

Oct 18th, 2020
2,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.83 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[crud_tst-mysql_updateField]
  2.     @itemID int,
  3.     @field nvarchar(64),
  4.     @value nvarchar(max),
  5.     @username nvarchar(64)
  6. AS
  7. BEGIN
  8.  
  9. declare @sql nvarchar(max) = ''
  10.  
  11. if(@field = 'p1') begin
  12.     set @sql = '
  13.       update openquery(MYSQL1, ''select data1 from RemotelyCreatedTable where id = '+cast(@itemID as nvarchar)+''' )  
  14.        set data1='''+@value+'''  
  15.        where data1 <> '''+@value+'''
  16.    '
  17.     EXEC (@sql)
  18.  
  19. end else if(@field = 'p2') begin
  20.     set @sql = '
  21.       update openquery(MYSQL1, ''select data2 from RemotelyCreatedTable where id = '+cast(@itemID as nvarchar)+''' )  
  22.        set data2='''+@value+'''  
  23.        where data2 <> '''+@value+'''
  24.    '
  25.     EXEC (@sql)
  26. end else begin
  27.     select 'Невалидный код свойства' Msg, 0 Result
  28.     return
  29. end  
  30. select '' Msg, 1 Result
  31.  
  32. END
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement