Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
?-- =============================================
-- Description: Cleans the Protocols
--
-- Maintenance Log:
--
-- Update By Update Date Description
-- ----------- --------- ----------------------------
-- =============================================
CREATE PROCEDURE zraw.[uspDoCleanProtocols]
AS
DECLARE @TABLE_NAME varchar(100); --make constant value for use thoughout
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
BEGIN TRY
--Set @TABLE_NAME value
SET @TABLE_NAME = 'zraw._dimProtocol';
--drop the #batchTable if it exists...
--SQL 2016 script-- DROP TABLE IF EXISTS #batchTableProtocols;
--SQL 2014 script--
--Drop temp table
IF OBJECT_ID(N'tempdb..#batchTableProtocols') IS NOT NULL
BEGIN
DROP TABLE #batchTableProtocols;
END
--need to restrict the records we modified to only those available for internalprocessing
SELECT BatchLogID, TableName, BatchDate
INTO #batchTableProtocols
FROM dbo.ufnGetBatchLogsForTableProcessing ('INTPROCESSING', @TABLE_NAME);
--LTRIM/RTRIM any string-based fields and Null out any empty strings
UPDATE zraw._dimProtocol SET
Protocol = NULLIF(LTRIM(RTRIM(Protocol)), '')
, OpCode = NULLIF(LTRIM(RTRIM(OpCode)), '')
WHERE EXISTS (SELECT 1 FROM #batchTableProtocols
WHERE zraw._dimProtocol.BatchLogID = #batchTableProtocols.BatchLogID);
/**
Protocol varchar(50) null, --field changes from numbers to text; source Protocol
**/
--set RecordStatusID based on OpCode
UPDATE zraw._dimProtocol SET
RecordStatusID = RecordStatuses.RecordStatusID
FROM RecordStatuses
INNER JOIN zraw._dimProtocol ON RecordStatuses.RecordStatusCode = zraw._dimProtocol.OpCode
WHERE EXISTS (SELECT 1 FROM #batchTableProtocols
WHERE zraw._dimProtocol.BatchLogID = #batchTableProtocols.BatchLogID);
--create any needed indexes to speed up cleaning
CREATE NONCLUSTERED INDEX IX_dimProtocol_Protocol ON zraw._dimProtocol
(
Protocol
) WITH (
PAD_INDEX = ON, --If want to use a Fill Factor, then PAD_INDEX must = ON
FILLFACTOR = 100, --100 = max fill; set to 90 if going to insert new values incrementally; 100 if doing bulk load
SORT_IN_TEMPDB = ON, -- sorts the index in the TempDB; default = OFF
IGNORE_DUP_KEY = OFF,
STATISTICS_NORECOMPUTE = OFF,
STATISTICS_INCREMENTAL = OFF,
DROP_EXISTING = OFF,
ONLINE = OFF,
ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON,
MAXDOP = 0, --degrees of parallelism, controls how many CPUs to use; 0 = default (all available), max = 64
DATA_COMPRESSION = PAGE --don't need, less than 10,000 rows
)
ON StagingIndex;
--drop any raw index objects
DROP INDEX IX_dimProtocol_Protocol
ON zraw._dimProtocol;
--drop the #batchTableProtocols if it exists...
--SQL 2016 script-- DROP TABLE IF EXISTS #batchTableProtocols;
--SQL 2014 script--
--Drop temp table
IF OBJECT_ID(N'tempdb..#batchTableProtocols') IS NOT NULL
BEGIN
DROP TABLE #batchTableProtocols;
END
END TRY
BEGIN CATCH
--identify that records in the batch have errored
UPDATE BatchLogs SET
LoadStatus = 'INTERROR'
WHERE EXISTS (SELECT 1 FROM #batchTableProtocols
WHERE BatchLogs.BatchLogID = #batchTableProtocols.BatchLogID);
--drop the #batchTableProtocols if it exists...
--SQL 2016 script-- DROP TABLE IF EXISTS #batchTableProtocols;
--SQL 2014 script--
--Drop temp table
IF OBJECT_ID(N'tempdb..#batchTableProtocols') IS NOT NULL
BEGIN
DROP TABLE #batchTableProtocols;
END
PRINT 'There was an error cleaning raw Request Service data' + CHAR(13);
THROW;
END CATCH
END