USE CCR;
GO

SET NOCOUNT ON;
SET XACT_ABORT ON;
SET ANSI_NULLS ON;
SET QUOTED_IDENTIFIER ON;
GO

IF DB_NAME() <> 'CCR'
BEGIN
    RAISERROR('Wrong database.', 16, 10);
    RETURN;
END;
GO

IF EXISTS (
    SELECT 1
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA = 'dbo'
      AND TABLE_NAME = 'InstantPaymentSystemTypes'
)
BEGIN
    INSERT INTO dbo.InstantPaymentSystemTypes (PaymentSystem)
    SELECT val.PaymentSystem
    FROM (
        VALUES
            ('Inst'),
            ('InstEU1'),
            ('InstEU2'),
            ('InstEU3'),
            ('InstEWR1'),
            ('InstEWR2'),
            ('InstEWR3'),
            ('InstNonEWR1'),
            ('InstNonOEWR2'),
            ('InstNonOEWR3')
    ) AS val(PaymentSystem)
    WHERE NOT EXISTS (
        SELECT 1 FROM dbo.InstantPaymentSystemTypes t WHERE t.PaymentSystem = val.PaymentSystem
    );
END

GO
