Advertisement
kromm77

[SQL_SERVER] Update Json

Jul 12th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.37 KB | None | 0 0
  1. with customprop as (
  2.     SELECT  
  3.     ea.CustomPropertiesJson,
  4.     JSON_VALUE ( ea.CustomPropertiesJson,'$.nomeProdotto')  as nomeProdotto ,
  5.     JSON_VALUE ( ea.CustomPropertiesJson,'$.nomeProdottoVisibileCreazioneIntervista')  as nomeProdottoVisibileCreazioneIntervista ,
  6.     JSON_VALUE ( ea.CustomPropertiesJson,'$.id')  as idJson ,
  7.     JSON_VALUE ( ea.CustomPropertiesJson,'$.apriFormat')  as apriFormat ,
  8.     JSON_VALUE ( ea.CustomPropertiesJson,'$.idMaster')  as idMaster ,
  9.     JSON_VALUE ( ea.CustomPropertiesJson,'$.idModelloDaInviare')  as idModelloDaInviare ,
  10.     ISNUMERIC(code) is_numeric,
  11.     --JSON_MODIFY ( ea.CustomPropertiesJson , '$.idModelloDaInviare' , CAST(code AS NUMERIC(12,0)) ) as newIdModello,
  12.     ea.Id,
  13.     ea.Description,
  14.     ea.Code
  15.     FROM [Finservice.SurveyDb.Test].[dbo].[EventArguments] as  ea) ,
  16.     ncustomprop as (
  17.     select id,idJson,nomeProdotto,Description,apriFormat,idMaster,idModelloDaInviare,JSON_MODIFY (  CustomPropertiesJson , '$.idModelloDaInviare' , CAST(code AS NUMERIC(12,0)) ) as newIdModello
  18.     from customprop
  19.     where is_numeric = 1 and idModelloDaInviare= -1
  20.   )
  21.   --select  from ncustomprop
  22.   update  [Finservice.SurveyDb.Test].[dbo].[EventArguments]
  23. set CustomPropertiesJson = ncustomprop.newIdModello
  24. from   ncustomprop join [Finservice.SurveyDb.Test].[dbo].[EventArguments] on [Finservice.SurveyDb.Dev_Server].[dbo].[EventArguments].id = ncustomprop.id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement