sync
This commit is contained in:
7
cds restore check.sql
Normal file
7
cds restore check.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
USE sandbox
|
||||
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
|
||||
|
||||
SELECT CAST([LogDateTime] AS DATE) AS [day], COUNT(1) AS cnt
|
||||
FROM [cds_log]
|
||||
GROUP BY CAST([LogDateTime] AS DATE)
|
||||
ORDER BY CAST([LogDateTime] AS DATE) DESC
|
||||
308
gaia test queue sending.sql
Normal file
308
gaia test queue sending.sql
Normal file
@@ -0,0 +1,308 @@
|
||||
USE gaia
|
||||
GO
|
||||
DECLARE
|
||||
@galenicaQueueID UNIQUEIDENTIFIER,
|
||||
@storageAccountName VARCHAR(MAX) = 'sttpsuntestphaqueues',
|
||||
@queue VARCHAR(63) = 'sun004-triafin',
|
||||
@payload VARCHAR(MAX)= '<Request RequestType="EntryCreate"><Data><EntryCreate><ReferencePharmacyId>706</ReferencePharmacyId><ReferenceOperationId>1215</ReferenceOperationId><OperationId>1215</OperationId><DebtorAccountId><PharmacyCode>GSU004</PharmacyCode><Id>136552</Id></DebtorAccountId><CreditorAccountId><PharmacyCode>GSU004</PharmacyCode><Id>1500090004</Id></CreditorAccountId><ReconciliationId><PharmacyCode>GSU004</PharmacyCode><Id>1501704897</Id></ReconciliationId><UserId>8231</UserId><ValueDate>2025-12-03</ValueDate><DocumentDate>2022-04-02</DocumentDate><Amount>48.4</Amount><Subject>BASSET JOSE - YUGRRP Hsnü - 1789 LUGNORRE</Subject><Remark>Zahlung ohne QRR</Remark><EntryInputMode>Excel</EntryInputMode><ConversationId>25306</ConversationId><ConversationCreationDate>2025-12-05T10:34:24</ConversationCreationDate></EntryCreate></Data></Request>',
|
||||
@headers VARCHAR(MAX),
|
||||
@headersBlob VARCHAR(MAX),
|
||||
@oldConversationID UNIQUEIDENTIFIER,
|
||||
@blobID UNIQUEIDENTIFIER,
|
||||
@messageTypeName VARCHAR(255) = 'CeresSenderMessageType',
|
||||
@statusCode INT,
|
||||
@statusText NVARCHAR(4000),
|
||||
@conversationID UNIQUEIDENTIFIER,
|
||||
@messageID UNIQUEIDENTIFIER,
|
||||
@insertionTime DATETIME
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
/* -------------------- VALIDATION -------------------- */
|
||||
|
||||
|
||||
/* -------------------- VARIABLES -------------------- */
|
||||
DECLARE @token VARCHAR(MAX),
|
||||
@credentialName VARCHAR(256) = NULL,
|
||||
@timeoutSeconds INT = 30,
|
||||
@response VARCHAR(MAX),
|
||||
@rawResponse XML,
|
||||
@finalURL VARCHAR(MAX),
|
||||
@ttl CHAR(13) = 'messagettl=-1',
|
||||
@source VARBINARY(MAX),
|
||||
@originalPayload VARCHAR(MAX) = @payload,
|
||||
@url VARCHAR(MAX),
|
||||
@urlblob VARCHAR(MAX),
|
||||
@returnValue INT = 0,
|
||||
@payloadBytes INT,
|
||||
@createURL VARCHAR(MAX),
|
||||
@retryCount INT,
|
||||
@maxRetries INT,
|
||||
@retryDelaySeconds INT,
|
||||
@waitTime CHAR(8),
|
||||
@postURL VARCHAR(MAX);
|
||||
|
||||
|
||||
/* -------------------- GET TOKEN -------------------- */
|
||||
IF @credentialName IS NULL
|
||||
BEGIN
|
||||
EXEC @returnValue = sp_get_Bearer_token
|
||||
@Token = @token OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT,
|
||||
@statusText = @statusText OUTPUT;
|
||||
|
||||
IF @returnValue <> 0 OR @statusCode <> 200
|
||||
RAISERROR('Error: Get token failed! statusCode: %d statusText: %s',16,1,@statusCode,@statusText);
|
||||
END
|
||||
|
||||
|
||||
/* -------------------- HEADERS -------------------- */
|
||||
IF @headers IS NULL
|
||||
SET @headers = CONCAT(
|
||||
'Content-Type: application/xml',CHAR(10),
|
||||
'x-ms-version: 2025-07-05',CHAR(10),
|
||||
'Authorization: Bearer ',@token,CHAR(10)
|
||||
);
|
||||
|
||||
IF @headersBlob IS NULL
|
||||
SET @headersBlob = CONCAT(
|
||||
'x-ms-blob-type: BlockBlob',CHAR(10),
|
||||
'x-ms-version: 2025-07-05',CHAR(10),
|
||||
'Authorization: Bearer ',@token,CHAR(10)
|
||||
);
|
||||
|
||||
|
||||
/* -------------------- PREPARE -------------------- */
|
||||
EXEC sp_manage_GalenicaQueue;
|
||||
|
||||
SELECT @conversationID = ISNULL(@oldConversationID,NEWID());
|
||||
|
||||
SET @url = CONCAT('https://',@storageAccountName,'.queue.core.windows.net/');
|
||||
SET @urlblob = CONCAT('https://',@storageAccountName,'.blob.core.windows.net/');
|
||||
|
||||
IF RIGHT(@queue,1) <> '/' SET @queue = CONCAT(@queue,'/');
|
||||
SET @queue = LOWER(@queue);
|
||||
|
||||
|
||||
/* -------------------- INSERT MONITORING -------------------- */
|
||||
IF @galenicaQueueID IS NULL
|
||||
BEGIN
|
||||
SET @galenicaQueueID = NEWID();
|
||||
|
||||
INSERT INTO GalenicaQueue(
|
||||
galenicaQueueID, conversationID, messageID,
|
||||
storageAccountName, queueName, headers,
|
||||
headersBlob, blobID, messageTypeName, payload
|
||||
) VALUES (
|
||||
@galenicaQueueID, @conversationID, @messageID,
|
||||
@storageAccountName, REPLACE(@queue,'/',''), @headers,
|
||||
@headersBlob, @blobID, @messageTypeName, @originalPayload
|
||||
);
|
||||
END
|
||||
|
||||
|
||||
/* -------------------- BLOB UPLOAD IF NEEDED -------------------- */
|
||||
SET @payloadBytes = DATALENGTH(@originalPayload);
|
||||
|
||||
IF @payloadBytes > 49152
|
||||
BEGIN
|
||||
IF @blobID IS NULL
|
||||
BEGIN
|
||||
EXEC @returnValue = sp_put_message_into_blob
|
||||
@url = @urlblob,
|
||||
@payload = @originalPayload,
|
||||
@headers = @headersBlob,
|
||||
@response = @response OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@blobID = @blobID OUTPUT;
|
||||
|
||||
IF @returnValue <> 0 RETURN;
|
||||
END
|
||||
END
|
||||
ELSE
|
||||
SET @blobID = NULL;
|
||||
|
||||
|
||||
/* -------------------- BUILD MESSAGE -------------------- */
|
||||
SET @postURL = CONCAT(@url,@queue,'messages?',CONCAT_WS('&',@ttl,NULLIF(@token,'')));
|
||||
|
||||
IF @blobID IS NULL
|
||||
SET @payload = CONCAT(
|
||||
'<GalenicaQueue><conversationID>',CONVERT(VARCHAR(255),@conversationID),
|
||||
'</conversationID><inlinePayload><![CDATA[',@originalPayload,
|
||||
']]></inlinePayload><messageTypeName>',@messageTypeName,
|
||||
'</messageTypeName></GalenicaQueue>'
|
||||
);
|
||||
ELSE
|
||||
SET @payload = CONCAT(
|
||||
'<GalenicaQueue><conversationID>',CONVERT(VARCHAR(255),@conversationID),
|
||||
'</conversationID><blobID>',CONVERT(VARCHAR(255),@blobID),
|
||||
'</blobID><messageTypeName>',@messageTypeName,
|
||||
'</messageTypeName></GalenicaQueue>'
|
||||
);
|
||||
|
||||
--cast the payload to xml first to enforce a utf-16le bytes encoding
|
||||
SET @source = CONVERT(VARBINARY(MAX), CONVERT(XML, @payload));
|
||||
SET @payload =
|
||||
CAST('' AS XML).value('xs:base64Binary(sql:variable("@source"))','varchar(max)');
|
||||
|
||||
SET @payload = CONCAT('<QueueMessage><MessageText>', @payload, '</MessageText></QueueMessage>');
|
||||
print @payload
|
||||
|
||||
/* -------------------- SEND MESSAGE FIRST TRY -------------------- */
|
||||
BEGIN TRY
|
||||
EXEC @returnValue = sp_Make_Restful_Call
|
||||
@url = @postURL,
|
||||
@method = 'POST',
|
||||
@payload = @payload,
|
||||
@headers = @headers,
|
||||
@credentialName = @credentialName,
|
||||
@timeoutSeconds = @timeoutSeconds,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT,
|
||||
@raiseError = 0 ;
|
||||
|
||||
IF @statusCode BETWEEN 400 AND 499
|
||||
RAISERROR('Error in make restfull call',16,10);
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
|
||||
|
||||
/* -------------------- QUEUE MISSING → CREATE IT -------------------- */
|
||||
IF @statusCode = 404
|
||||
BEGIN
|
||||
SET @createURL = CONCAT(@url,@queue,'?',@token);
|
||||
|
||||
EXEC @returnValue = sp_Make_Restful_Call
|
||||
@url = @createURL,
|
||||
@method = 'PUT',
|
||||
@payload = NULL,
|
||||
@headers = @headers,
|
||||
@credentialName = @credentialName,
|
||||
@timeoutSeconds = @timeoutSeconds,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT;
|
||||
|
||||
|
||||
/* -------------------- 409 CONFLICT → RETRY + CLEANUP -------------------- */
|
||||
IF @statusCode = 409
|
||||
BEGIN
|
||||
SET @retryCount = 0;
|
||||
SET @maxRetries = 10;
|
||||
SET @retryDelaySeconds = 10;
|
||||
|
||||
WHILE @retryCount < @maxRetries
|
||||
BEGIN
|
||||
EXEC @returnValue = sp_Make_Restful_Call
|
||||
@url = @createURL,
|
||||
@method = 'PUT',
|
||||
@payload = NULL,
|
||||
@headers = @headers,
|
||||
@credentialName = @credentialName,
|
||||
@timeoutSeconds = @timeoutSeconds,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT;
|
||||
|
||||
IF @statusCode IN (201,204)
|
||||
BREAK;
|
||||
|
||||
/* Cleanup blob if needed */
|
||||
IF @blobID IS NOT NULL
|
||||
BEGIN
|
||||
EXEC @returnValue = sp_delete_message_from_blob
|
||||
@storageAccountName = @storageAccountName,
|
||||
@headers = @headersBlob,
|
||||
@blobID = @blobID,
|
||||
@response = @response OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT,
|
||||
@statusText = @statusText OUTPUT;
|
||||
END
|
||||
|
||||
/* Wait */
|
||||
SET @waitTime = CONCAT('00:00:', RIGHT('0'+CAST(@retryDelaySeconds AS VARCHAR(2)),2));
|
||||
WAITFOR DELAY @waitTime;
|
||||
|
||||
SET @retryCount += 1;
|
||||
END
|
||||
|
||||
IF @statusCode NOT IN (201,204)
|
||||
RAISERROR(
|
||||
'Error: Create the queue failed after %d retries! statusCode: %d statusText: %s',
|
||||
16,1,@retryCount,@statusCode,@statusText
|
||||
);
|
||||
END
|
||||
|
||||
/* Retry sending */
|
||||
EXEC @returnValue = sp_Make_Restful_Call
|
||||
@url = @postURL,
|
||||
@method = 'POST',
|
||||
@payload = @payload,
|
||||
@headers = @headers,
|
||||
@credentialName = @credentialName,
|
||||
@timeoutSeconds = @timeoutSeconds,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT;
|
||||
END
|
||||
|
||||
END CATCH
|
||||
|
||||
return
|
||||
|
||||
|
||||
|
||||
/* -------------------- UPDATE MONITORING -------------------- */
|
||||
UPDATE GalenicaQueue
|
||||
SET blobID = @blobID,
|
||||
statusCode = @statusCode,
|
||||
statusText = @statusText,
|
||||
response = @response
|
||||
WHERE galenicaQueueID = @galenicaQueueID;
|
||||
|
||||
|
||||
/* -------------------- FINAL VALIDATION -------------------- */
|
||||
IF @returnValue <> 0 OR @statusCode NOT BETWEEN 200 and 299
|
||||
RAISERROR('Error: Create the message into the queue failed! statusCode: %d statusText: %s',
|
||||
16,1,@statusCode,@statusText);
|
||||
|
||||
|
||||
/* -------------------- PARSE RESPONSE -------------------- */
|
||||
SET @rawResponse = CAST(@response AS XML);
|
||||
|
||||
SELECT @messageID = msg.value('(MessageId)[1]','UNIQUEIDENTIFIER'),
|
||||
@insertionTime =
|
||||
CONVERT(DATETIME,
|
||||
CAST(
|
||||
LTRIM(RTRIM(
|
||||
REPLACE(
|
||||
SUBSTRING(
|
||||
msg.value('(InsertionTime)[1]','VARCHAR(MAX)'),
|
||||
CHARINDEX(',',msg.value('(InsertionTime)[1]','VARCHAR(MAX)'))+1,
|
||||
LEN(msg.value('(InsertionTime)[1]','VARCHAR(MAX)'))
|
||||
),
|
||||
'GMT',''
|
||||
)
|
||||
))
|
||||
AS DATETIMEOFFSET)
|
||||
AT TIME ZONE 'UTC'
|
||||
AT TIME ZONE 'Central European Standard Time')
|
||||
FROM @rawResponse.nodes('/QueueMessagesList/QueueMessage') AS T(msg);
|
||||
|
||||
|
||||
UPDATE GalenicaQueue
|
||||
SET messageID = @messageID,
|
||||
blobID = @blobID,
|
||||
statusCode = @statusCode,
|
||||
statusText = @statusText,
|
||||
response = @response,
|
||||
insertionTime = @insertionTime
|
||||
WHERE galenicaQueueID = @galenicaQueueID;
|
||||
|
||||
END
|
||||
|
||||
|
||||
GO
|
||||
66
paul_snippets/check production times.sql
Normal file
66
paul_snippets/check production times.sql
Normal file
@@ -0,0 +1,66 @@
|
||||
USE JOB
|
||||
GO
|
||||
|
||||
|
||||
DECLARE @Jobs TABLE(JobKey_Start INT, JobKey_End INT, Jobname NVARCHAR(50), INDEX Idx_JobKey_Start NONCLUSTERED (JobKey_Start), INDEX Idx_JobKey_End NONCLUSTERED (JobKey_End))
|
||||
|
||||
|
||||
INSERT INTO @Jobs (JobKey_Start, JobKey_End, Jobname)
|
||||
SELECT JOB_KEY AS JobKey_Start, dbo.fn_GetJobEnd(JOB_KEY) AS JobKey_End, JOBNAME
|
||||
FROM dbo.JOB_STATE
|
||||
WHERE [STATE] = 'RUNNING'
|
||||
AND ENTRYDATE BETWEEN '2025-12-01' AND '2026-03-01'
|
||||
AND (JOBNAME LIKE 'IndexProdukte[_]%' OR
|
||||
JOBNAME LIKE 'IndexViewer[_]%' OR
|
||||
JOBNAME LIKE 'Product[_]%')
|
||||
--SELECT DISTINCT Jobname FROM @Jobs
|
||||
|
||||
SELECT
|
||||
CONVERT(NVARCHAR(16), StartDt, 104) AS StartDt,
|
||||
--DATENAME(WEEKDAY, StartDt) AS [Day],
|
||||
SUM(res.IndexProdukte__Generate__XML_Data) AS IndexProdukte__Generate__XML_Data,
|
||||
SUM(res.IndexProdukte__Import__SourceData) AS IndexProdukte__Import__SourceData,
|
||||
SUM(res.IndexProdukte__Publish__for_QS) AS IndexProdukte__Publish__for_QS,
|
||||
SUM(res.IndexProdukte__QS_Data_Integrity_Checks) AS IndexProdukte__QS_Data_Integrity_Checks,
|
||||
SUM(res.IndexProdukte__Update__Stamm_Daten) AS IndexProdukte__Update__Stamm_Daten,
|
||||
SUM(res.IndexProdukte__Update__Work_Stamm_Daten) AS IndexProdukte__Update__Work_Stamm_Daten,
|
||||
SUM(res.IndexViewer__DL__insureINDEX) AS IndexViewer__DL__insureINDEX,
|
||||
SUM(res.IndexViewer__DL_UL__Daily) AS IndexViewer__DL_UL__Daily,
|
||||
SUM(res.IndexViewer__UL__insureINDEX) AS IndexViewer__UL__insureINDEX,
|
||||
SUM(res.Product__Generate_Superset) AS Product__Generate_Superset
|
||||
FROM (
|
||||
SELECT CAST(StartDt AS DATE) AS StartDt,
|
||||
IndexProdukte__Generate__XML_Data,
|
||||
IndexProdukte__Import__SourceData,
|
||||
IndexProdukte__Publish__for_QS,
|
||||
IndexProdukte__QS_Data_Integrity_Checks,
|
||||
IndexProdukte__Update__Stamm_Daten,
|
||||
IndexProdukte__Update__Work_Stamm_Daten,
|
||||
IndexViewer__DL__insureINDEX,
|
||||
IndexViewer__DL_UL__Daily,
|
||||
IndexViewer__UL__insureINDEX,
|
||||
Product__Generate_Superset
|
||||
FROM (
|
||||
SELECT jss.JOBNAME, jss.ENTRYDATE AS [StartDt], jse.ENTRYDATE AS [EndDt], (DATEDIFF(MINUTE, jss.ENTRYDATE, jse.ENTRYDATE)) AS Duration
|
||||
FROM @Jobs AS js
|
||||
INNER JOIN dbo.JOB_STATE AS jss ON js.JobKey_Start = jss.JOB_KEY
|
||||
INNER JOIN dbo.JOB_STATE AS jse ON js.JobKey_End = jse.JOB_KEY
|
||||
) AS t
|
||||
PIVOT (
|
||||
SUM(Duration)
|
||||
FOR JOBNAME IN (
|
||||
IndexProdukte__Generate__XML_Data,
|
||||
IndexProdukte__Import__SourceData,
|
||||
IndexProdukte__Publish__for_QS,
|
||||
IndexProdukte__QS_Data_Integrity_Checks,
|
||||
IndexProdukte__Update__Stamm_Daten,
|
||||
IndexProdukte__Update__Work_Stamm_Daten,
|
||||
IndexViewer__DL__insureINDEX,
|
||||
IndexViewer__DL_UL__Daily,
|
||||
IndexViewer__UL__insureINDEX,
|
||||
Product__Generate_Superset
|
||||
)
|
||||
) AS pivot_table
|
||||
) AS res
|
||||
GROUP BY res.StartDt
|
||||
ORDER BY res.StartDt ASC
|
||||
394
test 000400.Initialize_InsuranceNetworkServiceAdvice.sql
Normal file
394
test 000400.Initialize_InsuranceNetworkServiceAdvice.sql
Normal file
@@ -0,0 +1,394 @@
|
||||
USE [Arizona]
|
||||
GO
|
||||
BEGIN TRANSACTION
|
||||
|
||||
SET ANSI_NULLS ON
|
||||
SET ANSI_WARNINGS ON
|
||||
go
|
||||
|
||||
/*
|
||||
Script pour la mise à jour de la table [InsuranceNetworkServiceAdvice]
|
||||
25.08.2025 / FLA pour le bug OCTP-9752
|
||||
|
||||
Modifications
|
||||
29.10.2025 TSC TPDT-1391 Removed linked server usage
|
||||
11.11.2025 TSC TPDT-1391 Removed dbo.xxx instance in remote code
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------*/
|
||||
|
||||
IF(NOT EXISTS (SELECT 1 FROM [InstanceContext] WHERE [Business] = 'TPCENT'))
|
||||
BEGIN
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
/* variables for linked server replacement */
|
||||
DECLARE @host_central VARCHAR(200);
|
||||
DECLARE @host_local VARCHAR(200);
|
||||
DECLARE @query VARCHAR(MAX);
|
||||
DECLARE @payload VARCHAR(MAX);
|
||||
DECLARE @response NVARCHAR(MAX);
|
||||
DECLARE @statusText NVARCHAR(4000);
|
||||
DECLARE @statusCode INT;
|
||||
DECLARE @azFuncUri VARCHAR(500);
|
||||
--for output handling
|
||||
DECLARE @format NVARCHAR(MAX);
|
||||
DECLARE @data NVARCHAR(MAX);
|
||||
DECLARE @tpl NVARCHAR(MAX);
|
||||
DECLARE @q NVARCHAR(MAX);
|
||||
|
||||
SELECT @host_central = hostname
|
||||
FROM aps_fn_fetch_central_hostname(DEFAULT);
|
||||
|
||||
SELECT @host_local = fqdn_escaped
|
||||
FROM aps_fn_fetch_local_instance_fqdn();
|
||||
|
||||
SELECT @azFuncUri = url
|
||||
FROM aps_fn_fetch_az_func_url();
|
||||
|
||||
SET @payload='
|
||||
{
|
||||
"QueryText": "SELECT 1 AS enabled FROM @dbo@.aps_monitor_table WHERE AMT_table_name = ''Insurance_netw_serv_advice'' AND AMT_vertical_synchronization = 1"
|
||||
,"Parameters": {}
|
||||
, "TargetServer": @host@
|
||||
, "TargetDbName": "arizona"
|
||||
, "Credential": "sqlLksrvTpCentAdm"
|
||||
}';
|
||||
SET @payload = REPLACE(@payload, '@host@', isnull('"'+@host_central+'"', 'null'));
|
||||
SET @payload = REPLACE(@payload, '@dbo@','dbo');
|
||||
|
||||
EXEC [sp_Make_Restful_Call] @url = @azFuncUri,
|
||||
@method = 'POST',
|
||||
@payload = @payload,
|
||||
@headers = DEFAULT,
|
||||
@credentialName = NULL,
|
||||
@timeoutSeconds = 10,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT;
|
||||
IF @statusCode NOT BETWEEN 200 and 299
|
||||
BEGIN
|
||||
RAISERROR('Error when calling Azure Function: %s (Status code: %d). %s', 16, 1, @statusText, @statusCode, @payload);
|
||||
RETURN;
|
||||
END
|
||||
SELECT @format = [Value]
|
||||
FROM OPENJSON(@response)
|
||||
WHERE [Key] = 'schemaFormatted';
|
||||
|
||||
SELECT @data = [Value]
|
||||
FROM OPENJSON(@response)
|
||||
WHERE [Key] = 'data';
|
||||
|
||||
IF OBJECT_ID('tempdb..#vsync_config')IS NOT NULL BEGIN
|
||||
DROP TABLE #vsync_config;
|
||||
END
|
||||
CREATE TABLE #vsync_config([enabled] BIT NOT NULL);
|
||||
SET @tpl = N'
|
||||
INSERT INTO #vsync_config
|
||||
SELECT *
|
||||
FROM OPENJSON(''@data@'')
|
||||
@format@
|
||||
';
|
||||
|
||||
SET @q = REPLACE(REPLACE(@tpl, '@data@', @data), '@format@', @format);
|
||||
|
||||
EXEC (@q);
|
||||
|
||||
IF EXISTS (SELECT 1 FROM [#vsync_config] c WHERE c.[enabled] = 1)
|
||||
BEGIN
|
||||
|
||||
DECLARE @cvCurrentOrganizationalUnit INT,
|
||||
@out_default_value VARCHAR(60)
|
||||
|
||||
IF OBJECT_ID('tempdb..#v_Sync_V_Insurance_netw_serv_advice')IS NOT NULL BEGIN
|
||||
DROP TABLE #v_Sync_V_Insurance_netw_serv_advice;
|
||||
END
|
||||
CREATE TABLE #v_Sync_V_Insurance_netw_serv_advice(
|
||||
calc_subsidiary_id INT NULL,
|
||||
Insurance_netw_serv_advice_ID INT NULL,
|
||||
INSA_Advice_Enum TINYINT NULL,
|
||||
INSA_Insurance_Network_ID INT NULL,
|
||||
INSA_Item_ID INT NULL
|
||||
);
|
||||
|
||||
EXEC sp_bmc_Bmc_Applic_Default
|
||||
@in_job_type = 3,
|
||||
@in_param_int_1 = NULL,
|
||||
@in_param_int_2 = NULL,
|
||||
@in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
|
||||
@out_default_value = @out_default_value OUTPUT,
|
||||
@out_param_int_1 = NULL;
|
||||
|
||||
SET @cvCurrentOrganizationalUnit = convert(int,@out_default_value);
|
||||
|
||||
/* Fetch data from central */
|
||||
SET @query = '
|
||||
SELECT *
|
||||
FROM @dbo@.v_Sync_V_Insurance_netw_serv_advice
|
||||
';
|
||||
SET @query = REPLACE(@query, '@dbo@','dbo');
|
||||
--JSON param must be without carriage return, remove them from the query to execute
|
||||
SET @query = REPLACE(REPLACE(@query, CHAR(13), ' '), CHAR(10), ' ');
|
||||
|
||||
set @payload='
|
||||
{
|
||||
"QueryText": @query@
|
||||
,"Parameters": {}
|
||||
, "TargetServer": @host@
|
||||
, "TargetDbName": "arizona"
|
||||
, "Credential": "sqlLksrvTpCentAdm"
|
||||
, "InjectResults": true
|
||||
, "InjectServer": @local@
|
||||
, "InjectDbName": "arizona"
|
||||
, "InjectDbSchema": "bulk"
|
||||
}';
|
||||
|
||||
SET @payload = REPLACE(@payload, '@query@', isnull('"'+@query+'"', 'null'));
|
||||
SET @payload = REPLACE(@payload, '@host@', isnull('"'+@host_central+'"', 'null'));
|
||||
SET @payload = REPLACE(@payload, '@local@', isnull('"'+@host_local+',1433"', 'null'));
|
||||
|
||||
EXEC [sp_Make_Restful_Call] @url = @azFuncUri,
|
||||
@method = 'POST',
|
||||
@payload = @payload,
|
||||
@headers = DEFAULT,
|
||||
@credentialName = NULL,
|
||||
@timeoutSeconds = 10,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT;
|
||||
|
||||
IF @statusCode NOT BETWEEN 200 and 299
|
||||
BEGIN
|
||||
RAISERROR('Error when calling Azure Function: %s (Status code: %d). %s', 16, 1, @statusText, @statusCode, @payload);
|
||||
RETURN;
|
||||
END
|
||||
|
||||
DECLARE @tbl VARCHAR(255);
|
||||
SELECT @tbl = [Value]
|
||||
FROM OPENJSON(@response)
|
||||
WHERE [Key]='TableName';
|
||||
|
||||
SET @tpl = N'
|
||||
INSERT INTO #v_Sync_V_Insurance_netw_serv_advice([calc_subsidiary_id], [Insurance_netw_serv_advice_ID], [INSA_Advice_Enum], [INSA_Insurance_Network_ID], [INSA_Item_ID])
|
||||
SELECT [calc_subsidiary_id], [Insurance_netw_serv_advice_ID], [INSA_Advice_Enum], [INSA_Insurance_Network_ID], [INSA_Item_ID]
|
||||
FROM @tbl@;
|
||||
|
||||
DROP TABLE @tbl@;
|
||||
';
|
||||
|
||||
SET @q = REPLACE(@tpl, '@tbl@', @tbl);
|
||||
EXEC (@q);
|
||||
|
||||
-- region managing insurance_network table
|
||||
set @query='
|
||||
SELECT
|
||||
[Insurance_network_ID], [INN_PH_insurance], [INN_ofac_code], [INN_veka_code], [INN_active], [INN_master_ID],
|
||||
[Insurance_network_text_ID], [INNT_language], [INNT_insurance_network], [INNT_text], [INNT_master_ID], [INNT_documentation_url]
|
||||
FROM [v_Sync_V_Insurance_network] n
|
||||
INNER JOIN [v_Sync_V_Insurance_network_text] nt on nt.[INNT_insurance_network] = n.[Insurance_network_ID] and nt.[calc_subsidiary_id] = n.[calc_subsidiary_id]
|
||||
WHERE n.[calc_subsidiary_id]=@sub
|
||||
'
|
||||
set @query = REPLACE(REPLACE(@query, CHAR(13), ' '), CHAR(10), ' ');
|
||||
|
||||
SET @payload = '
|
||||
{
|
||||
"QueryText": @query@
|
||||
,"Parameters": {"sub": @sub@}
|
||||
, "TargetServer": @host@
|
||||
, "TargetDbName": "arizona"
|
||||
, "Credential": "sqlLksrvTpCentAdm"
|
||||
, "InjectResults": true
|
||||
, "InjectServer": @local@
|
||||
, "InjectDbName": "arizona"
|
||||
, "InjectDbSchema": "bulk"
|
||||
}
|
||||
';
|
||||
SET @payload = REPLACE(@payload, '@host@', isnull('"'+@host_central+'"', 'null'));
|
||||
SET @payload = REPLACE(@payload, '@local@', isnull('"'+@host_local+',1433"', 'null'));
|
||||
SET @payload = REPLACE(@payload, '@query@', isnull('"'+@query+'"', 'null'));
|
||||
set @payload = REPLACE(@payload, '@sub@', convert(varchar(36), (SELECT TOP 1 ou.OU_subsidiary
|
||||
FROM Organizational_unit ou with (nolock)
|
||||
WHERE ou.Organizational_unit_ID = @cvCurrentOrganizationalUnit)));
|
||||
EXEC [sp_Make_Restful_Call] @url = @azFuncUri,
|
||||
@method = 'POST',
|
||||
@payload = @payload,
|
||||
@headers = DEFAULT,
|
||||
@credentialName = NULL,
|
||||
@timeoutSeconds = 10,
|
||||
@response = @response OUTPUT,
|
||||
@statusText = @statusText OUTPUT,
|
||||
@statusCode = @statusCode OUTPUT;
|
||||
IF @statusCode NOT BETWEEN 200 and 299
|
||||
BEGIN
|
||||
RAISERROR('Error when calling Azure Function: %s (Status code: %d). %s', 16, 1, @statusText, @statusCode, @payload);
|
||||
RETURN;
|
||||
END
|
||||
|
||||
DECLARE @tbl_insurance_network VARCHAR(255);
|
||||
SELECT @tbl_insurance_network = [Value]
|
||||
FROM OPENJSON(@response)
|
||||
WHERE [Key]='TableName';
|
||||
|
||||
IF OBJECT_ID('tempdb..#insurance_network')IS NOT NULL
|
||||
BEGIN
|
||||
DROP TABLE #insurance_network;
|
||||
END
|
||||
|
||||
CREATE TABLE #insurance_network(
|
||||
[Insurance_network_ID] int,
|
||||
[INN_PH_insurance] uniqueidentifier,
|
||||
[INN_ofac_code] varchar(20),
|
||||
[INN_veka_code] varchar(20),
|
||||
[INN_active] bit,
|
||||
[INN_master_ID] int,
|
||||
[Insurance_network_text_ID] int,
|
||||
[INNT_language] int,
|
||||
[INNT_insurance_network] int,
|
||||
[INNT_text] varchar(40),
|
||||
[INNT_master_ID] int,
|
||||
[INNT_documentation_url] varchar(2048)
|
||||
);
|
||||
SET @tpl = N'
|
||||
INSERT INTO #insurance_network([Insurance_network_ID], [INN_PH_insurance], [INN_ofac_code], [INN_veka_code], [INN_active], [INN_master_ID], [Insurance_network_text_ID], [INNT_language], [INNT_insurance_network], [INNT_text], [INNT_master_ID], [INNT_documentation_url])
|
||||
SELECT [Insurance_network_ID], [INN_PH_insurance], [INN_ofac_code], [INN_veka_code], [INN_active], [INN_master_ID], [Insurance_network_text_ID], [INNT_language], [INNT_insurance_network], [INNT_text], [INNT_master_ID], [INNT_documentation_url]
|
||||
FROM @tbl@;
|
||||
|
||||
DROP TABLE @tbl@;
|
||||
';
|
||||
|
||||
SET @q = REPLACE(@tpl, '@tbl@', @tbl_insurance_network);
|
||||
EXEC (@q);
|
||||
|
||||
--SELECT *
|
||||
UPDATE t
|
||||
SET t.[INN_PH_insurance] = s.[INN_PH_insurance],
|
||||
t.[INN_ofac_code] = s.[INN_ofac_code],
|
||||
t.[INN_veka_code] = s.[INN_veka_code],
|
||||
t.[INN_active] = s.[INN_active],
|
||||
t.[INN_master_ID] = s.[INN_master_ID]
|
||||
FROM [Insurance_network] t
|
||||
JOIN (
|
||||
SELECT DISTINCT
|
||||
[Insurance_network_ID]
|
||||
,[INN_PH_insurance]
|
||||
,[INN_ofac_code]
|
||||
,[INN_veka_code]
|
||||
,[INN_active]
|
||||
,[INN_master_ID]
|
||||
FROM [#insurance_network]
|
||||
)s ON s.[Insurance_network_ID] = t.[Insurance_network_ID]
|
||||
WHERE s.[INN_PH_insurance] <> t.[INN_PH_insurance]
|
||||
OR s.[INN_ofac_code] <> t.[INN_ofac_code]
|
||||
OR s.[INN_veka_code] <> t.[INN_veka_code]
|
||||
OR s.[INN_active] <> t.[INN_active]
|
||||
OR s.[INN_master_ID] <> t.[INN_master_ID];
|
||||
PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - Updated values on [Insurance_network]. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';
|
||||
|
||||
INSERT INTO [Insurance_network] ([Insurance_network_ID],
|
||||
[INN_PH_insurance],
|
||||
[INN_ofac_code],
|
||||
[INN_veka_code],
|
||||
[INN_active],
|
||||
[INN_master_ID])
|
||||
SELECT DISTINCT
|
||||
[Insurance_network_ID],
|
||||
[INN_PH_insurance],
|
||||
[INN_ofac_code],
|
||||
[INN_veka_code],
|
||||
[INN_active],
|
||||
[INN_master_ID]
|
||||
FROM [#insurance_network] s
|
||||
WHERE NOT EXISTS(
|
||||
SELECT 1
|
||||
FROM [Insurance_network] t
|
||||
WHERE s.[Insurance_network_ID] = t.[Insurance_network_ID]
|
||||
);
|
||||
PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - inserted missing [Insurance_network]. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';
|
||||
|
||||
UPDATE t
|
||||
SET t.[INNT_language] = s.[INNT_language]
|
||||
, t.[INNT_insurance_network] = s.[INNT_insurance_network]
|
||||
, t.[INNT_text] = s.[INNT_text]
|
||||
, t.[INNT_master_ID] = s.[INNT_master_ID]
|
||||
, t.[INNT_documentation_url] = s.[INNT_documentation_url]
|
||||
FROM [Insurance_network_text] t
|
||||
JOIN (
|
||||
SELECT DISTINCT
|
||||
[Insurance_network_text_ID],
|
||||
[INNT_language],
|
||||
[INNT_insurance_network],
|
||||
[INNT_text],
|
||||
[INNT_master_ID],
|
||||
[INNT_documentation_url]
|
||||
FROM [#insurance_network]
|
||||
)s ON s.[Insurance_network_text_ID] =t.[Insurance_network_text_ID]
|
||||
WHERE s.[INNT_language] <> t.[INNT_language]
|
||||
OR s.[INNT_insurance_network] <> t.[INNT_insurance_network]
|
||||
OR s.[INNT_text] <> t.[INNT_text]
|
||||
OR s.[INNT_master_ID] <> t.[INNT_master_ID]
|
||||
OR s.[INNT_documentation_url] <> t.[INNT_documentation_url]
|
||||
;
|
||||
PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - Updated existing values on [Insurance_network_text]. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';
|
||||
|
||||
INSERT INTO [Insurance_network_text] ([Insurance_network_text_ID],
|
||||
[INNT_language],
|
||||
[INNT_insurance_network],
|
||||
[INNT_text],
|
||||
[INNT_master_ID],
|
||||
[INNT_documentation_url])
|
||||
SELECT DISTINCT
|
||||
[Insurance_network_text_ID],
|
||||
[INNT_language],
|
||||
[INNT_insurance_network],
|
||||
[INNT_text],
|
||||
[INNT_master_ID],
|
||||
[INNT_documentation_url]
|
||||
FROM [#insurance_network] s
|
||||
WHERE NOT EXISTS(
|
||||
SELECT 1
|
||||
FROM [Insurance_network_text] t
|
||||
WHERE t.[Insurance_network_text_ID] = s.[Insurance_network_text_ID]
|
||||
);
|
||||
PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - Added missing [Insurance_network_text]. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';
|
||||
|
||||
-- endregion
|
||||
|
||||
--#region update existing [Insurance_netw_serv_advice]
|
||||
UPDATE t
|
||||
SET t.[INSA_Advice_Enum] = s.[INSA_Advice_Enum],
|
||||
t.[INSA_Insurance_Network_ID] = s.[INSA_Insurance_Network_ID],
|
||||
t.[INSA_Item_ID] = s.[INSA_Item_ID]
|
||||
FROM [Insurance_netw_serv_advice] t
|
||||
JOIN [#v_Sync_V_Insurance_netw_serv_advice] s ON s.[Insurance_netw_serv_advice_ID] = t.[Insurance_netw_serv_advice_ID]
|
||||
WHERE t.[INSA_Advice_Enum] <> s.[INSA_Advice_Enum]
|
||||
OR t.[INSA_Item_ID] <> s.[INSA_Item_ID]
|
||||
OR ISNULL(t.[INSA_Insurance_Network_ID],-1) <> ISNULL(s.[INSA_Insurance_Network_ID],-1);
|
||||
PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - updated existing [Insurance_netw_serv_advice]. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';
|
||||
--#endregion update existing [Insurance_netw_serv_advice]
|
||||
|
||||
--#region update existing advices
|
||||
INSERT INTO [Insurance_netw_serv_advice] ([Insurance_netw_serv_advice_ID],
|
||||
[INSA_Advice_Enum],
|
||||
[INSA_Insurance_Network_ID],
|
||||
[INSA_Item_ID])
|
||||
SELECT
|
||||
[Insurance_netw_serv_advice_ID],
|
||||
[INSA_Advice_Enum],
|
||||
[INSA_Insurance_Network_ID],
|
||||
[INSA_Item_ID]
|
||||
FROM [#v_Sync_V_Insurance_netw_serv_advice] s
|
||||
WHERE NOT EXISTS(
|
||||
SELECT 1
|
||||
FROM [Insurance_netw_serv_advice] t
|
||||
WHERE t.[Insurance_netw_serv_advice_ID] = s.[Insurance_netw_serv_advice_ID]
|
||||
)
|
||||
AND NOT EXISTS(
|
||||
SELECT 1
|
||||
FROM [Insurance_netw_serv_advice] t
|
||||
WHERE t.INSA_Advice_Enum = s.INSA_Advice_Enum
|
||||
AND ISNULL(t.INSA_Insurance_Network_ID,-1) = ISNULL(s.INSA_Insurance_Network_ID,-1)
|
||||
AND t.INSA_Item_ID=s.INSA_Item_ID
|
||||
);
|
||||
PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - inserted missing [Insurance_netw_serv_advice]. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';
|
||||
|
||||
--#endregion update existing advices
|
||||
END
|
||||
END
|
||||
ROLLBACK TRANSACTION
|
||||
Reference in New Issue
Block a user