Handling Deletes and Active Flags in the Party Address Domain
Managing data quality and consistency in the Party Address Domain is critical for effective data governance in a Master Data Management (MDM) system. Challenges arise when the source system sends new address IDs for a party (individual or organization) or removes an existing address by sending a NULL value. Without proper handling, this can lead to duplicate, outdated, or inconsistent records. Below, we explore how to handle these scenarios and implement a framework to maintain a clean and accurate Party Address Domain.
Understanding the Problem
In the Party Address Domain, common challenges include:
Framework for Address Management in MDM
1. Define Business Rules
2. Metadata Schema
Enhance the Party Address table with the following attributes:
3. Handling Scenarios
Scenario 1: New Address Record
When a new address is received for a party:
SQL Example:
-- Mark previous active addresses as inactive
UPDATE PartyAddress
SET IsActive = 0,
EffectiveDate = GETDATE(),
UpdatedBy = 'ETL_Process'
WHERE PartyID = @PartyID
AND AddressType = @AddressType
AND IsActive = 1;
-- Insert new address record
INSERT INTO PartyAddress (PartyID, AddressID, AddressType, AddressDetails, IsActive, EffectiveDate, UpdatedBy)
VALUES (@PartyID, @NewAddressID, @AddressType, @AddressDetails, 1, GETDATE(), 'ETL_Process');
Scenario 2: Address ID is NULL in Incremental Updates
When a source sends NULL for the Address ID, indicating the party no longer has a valid address for that type:
SQL Example:
-- Mark active address as inactive when NULL is received
UPDATE PartyAddress
SET IsActive = 0,
EffectiveDate = GETDATE(),
UpdatedBy = 'ETL_Process'
WHERE PartyID = @PartyID
AND AddressType = @AddressType
AND IsActive = 1;
-- Optional: Insert a placeholder record for "No Address"
INSERT INTO PartyAddress (PartyID, AddressID, AddressType, AddressDetails, IsActive, EffectiveDate, UpdatedBy)
VALUES (@PartyID, NULL, @AddressType, 'No Address Available', 0, GETDATE(), 'ETL_Process');
4. Automating the Process
Stored Procedure: Managing Active/Inactive Flags
Create a stored procedure to handle new, updated, and NULL Address IDs:
CREATE PROCEDURE ManagePartyAddress
@PartyID INT,
@AddressID INT = NULL,
@AddressType VARCHAR(50),
@AddressDetails VARCHAR(255)
AS
BEGIN
-- Deactivate existing active records
UPDATE PartyAddress
SET IsActive = 0,
EffectiveDate = GETDATE(),
UpdatedBy = 'ETL_Process'
WHERE PartyID = @PartyID
AND AddressType = @AddressType
AND IsActive = 1;
-- Handle new address
IF @AddressID IS NOT NULL
BEGIN
INSERT INTO PartyAddress (PartyID, AddressID, AddressType, AddressDetails, IsActive, EffectiveDate, UpdatedBy)
VALUES (@PartyID, @AddressID, @AddressType, @AddressDetails, 1, GETDATE(), 'ETL_Process');
END
ELSE
BEGIN
-- Optional: Add placeholder for NULL AddressID
INSERT INTO PartyAddress (PartyID, AddressID, AddressType, AddressDetails, IsActive, EffectiveDate, UpdatedBy)
VALUES (@PartyID, NULL, @AddressType, 'No Address Available', 0, GETDATE(), 'ETL_Process');
END
END;
5. Audit and Monitoring
Validation Query:
-- Identify duplicate active addresses
SELECT PartyID, AddressType, COUNT(*)
FROM PartyAddress
WHERE IsActive = 1
GROUP BY PartyID, AddressType
HAVING COUNT(*) > 1;
6. Example Input and Output
Benefits of the Framework
By implementing this framework, the Party Address Domain in your MDM will remain consistent, reliable, and aligned with business rules.