-- Merge statement for MSSQL (equivalent to INSERT ... ON DUPLICATE KEY UPDATE)
MERGE INTO packaging_property_type AS target
USING (VALUES
    (N'Stackable', 'STACKABLE', 'BOOLEAN', NULL, 0, N'desc', 'general', 1),
    (N'Rust Prevention', 'RUST_PREVENTION', 'BOOLEAN', NULL, 0, N'desc', 'general', 2),
    (N'Mixable', 'MIXABLE', 'BOOLEAN', NULL, 0, N'desc', 'general', 3)
) AS source (name, external_mapping_id, data_type, validation_rule, is_required, description, property_group, sequence_number)
ON target.external_mapping_id = source.external_mapping_id
WHEN MATCHED THEN
    UPDATE SET
        name = source.name,
        data_type = source.data_type
WHEN NOT MATCHED THEN
    INSERT (name, external_mapping_id, data_type, validation_rule, is_required, description, property_group, sequence_number)
    VALUES (source.name, source.external_mapping_id, source.data_type, source.validation_rule, source.is_required, source.description, source.property_group, source.sequence_number);
