The procedure has the following code which still produces NULL for notes somehow:
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
-- TRUNCATE TABLE #tempTable;
EXECUTE dbo.usp_File_Extract_ProviderMasterFile_VA_SPLIT @inp_region_nbr = @inp_region_nbr,
@inp_npi = @Npi,
@XMLVARCHAR = @Snapshot OUTPUT,
@providerid = @ProviderID OUTPUT;
--INSERT INTO #tempTable
--(
-- entity_id,
-- run_id,
-- partition_id, -- for splitting providers by Run/Partition ID
-- provider_id,
-- sha_value,
-- SNAPSHOT,
-- etl_create_dttm
--)
-- VALUES
--(@Npi
--, @inp_run_id
--, @inp_partition_id
--, @ProviderID
--, HASHBYTES('SHA2_512', @Snapshot)
--, @Snapshot
--, CAST(SYSDATETIMEOFFSET()AT TIME ZONE 'Central Standard Time' AS DATETIME2(7)));
/*
INSERT INTO
dbo.PROVIDER_EXTRACT_TEMP_MOD
(
entity_id
, run_id
, partition_id -- for splitting providers by Run/Partition ID
, provider_id
, sha_value
, snapshot
, etl_create_dttm
)
VALUES
(@Npi
, @inp_run_id
, @inp_partition_id
, @ProviderID
, HASHBYTES('SHA2_512', @Snapshot)
, @Snapshot
, CAST(SYSDATETIMEOFFSET()AT TIME ZONE 'Central Standard Time' AS DATETIME2(7)));
*/
IF LEN(@Snapshot) < 1067142
AND @Snapshot IS NOT NULL
INSERT INTO dbo.PROVIDER_EXTRACT_TEMP_MOD
(
entity_id,
run_id,
partition_id, -- for splitting providers by Run/Partition ID
provider_id,
sha_value,
snapshot,
etl_create_dttm
)
--SELECT entity_id,
-- run_id,
-- partition_id, -- for splitting providers by Run/Partition ID
-- provider_id,
-- sha_value,
-- SNAPSHOT,
-- etl_create_dttm
--FROM #tempTable;
VALUES
(@Npi
, @inp_run_id
, @inp_partition_id
, @ProviderID
, HASHBYTES('SHA2_512', @Snapshot)
, @Snapshot
, CAST(SYSDATETIMEOFFSET() AT TIME ZONE 'Central Standard Time' AS DATETIME2(7)));
ELSE
SET @notes = CONCAT('NPI ', @npi, ' is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for patrition ',
ISNULL(@inp_partition_id,0), ' LEN(@Snapshot) = ' , LEN(ISNULL(@Snapshot,'')) ,
' for region ' , CAST(@inp_region_nbr AS VARCHAR(20)), ERROR_MESSAGE())
EXECUTE dbo.usp_DevOps_Add_Exclusion_Mod @ExcludedId = @ProviderID,
@ExtractType = @inp_extract_type,
@notes = @notes;
FETCH NEXT FROM SplitProviderCursor
INTO @myrowid,
@Npi;
END TRY
BEGIN CATCH
-- Add exclusion
BEGIN TRY
SET @notes = CONCAT( 'NPI ' , isnull(@npi, '') , ' is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition ',
CONVERT(VARCHAR(10), ISNULL(@inp_partition_id,0)),
' for region ' , CAST(@inp_region_nbr AS VARCHAR(20)),' ', ERROR_MESSAGE()) ;
SET @notes = ISNULL(@notes,'No notes')
EXECUTE dbo.usp_DevOps_Add_Exclusion_Mod
@ExcludedId = @ProviderID
, @ExtractType = @inp_extract_type
, @notes = @notes;
END TRY
BEGIN CATCH
-- If this doesn't work, just audit error and keep going.
SET @audit_message_txt = CONCAT( 'Failed to exclude NPI ' , CONVERT(VARCHAR(20), ISNULL(@Npi, 0)) ,
' for region ' , CAST(@inp_run_id AS VARCHAR(10)) , ' ', ERROR_MESSAGE());
EXECUTE dbo.usp_write_audit
@inp_process_txt = @inp_process_txt
, @inp_sub_process_txt = @sub_process_txt
, @inp_type_id = 0
, @inp_action_txt = @audit_message_txt
, @inp_load_file_detail_id = @efd
, @inp_job_nbr = @inp_load_report_job_nbr;
END CATCH;
END CATCH;
END;
Which produces :
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NULL
Notes is NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
Notes is NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
Notes is NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
Notes is NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
Notes is NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
NPI 1053353896 is excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD for partition 1 for region 2 Arithmetic overflow error converting expression to data type varchar.
which I cannot figure out.
My colleague's code which is practically the same doesn't output messages at all:
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN TRY
EXECUTE dbo.usp_File_Extract_ProviderMasterFile_VA_SPLIT
@inp_region_nbr = @inp_region_nbr
, @inp_npi = @Npi
, @XMLVARCHAR = @Snapshot OUTPUT
, @providerid = @ProviderID OUTPUT;
INSERT INTO
dbo.PROVIDER_EXTRACT_TEMP_MOD
(
entity_id
, run_id
, partition_id -- for splitting providers by Run/Partition ID
, provider_id
, sha_value
, snapshot
, etl_create_dttm
)
VALUES
(@Npi
, @inp_run_id
, @inp_partition_id
, @ProviderID
, HASHBYTES('SHA2_512', @Snapshot)
, @Snapshot
, CAST(SYSDATETIMEOFFSET()AT TIME ZONE 'Central Standard Time' AS DATETIME2(7)));
FETCH NEXT FROM SplitProviderCursor
INTO
@myrowid
, @Npi;
END TRY
BEGIN CATCH
-- Add exclusion
BEGIN TRY
SET @notes = 'NPI excluded by usp_CREATE_SNAPSHOT_PER_PROVIDER_SPLIT_MOD ('
+ CONVERT(VARCHAR(10), ISNULL(@inp_partition_id,0)) + ')';
EXECUTE dbo.usp_DevOps_Add_Exclusion_Mod
@ExcludedId = @ProviderID
, @ExtractType = @inp_extract_type
, @notes = @notes;
--RAISERROR (@notes, 0, 1)
END TRY
BEGIN CATCH
I don't see much difference.