---------------------------------------------------------------------
-- SQL Server 2005ストアドプロシージャプログラミング
-- 第6章 エラー処理
---------------------------------------------------------------------

---------------------------------------------------------------------
-- 6.1 RAISERROR ステートメント
---------------------------------------------------------------------

RAISERROR(N'エラーが発生しました', 0, 1)


EXEC sp_addmessage 50001,
                   16,
                   N'Unable to update Total of LeaseSchedule',
                   'us_english',
                   'true'
GO
EXEC sp_addmessage 50001,
                   16,
                   N'リーススケジュールの総額を更新できません',
                   'Japanese'


RAISERROR (50001, 16, 1)


RAISERROR (50001, 16, 1) WITH LOG


EXEC sp_addmessage 50002,
                   16
                   N'Unable to update %s.',
                   'us_english',
                   'true'
GO
EXEC sp_addmessage 50002,
                   16,
                   N'%1!を更新できません',
                   'Japanese'


RAISERROR (50002, 16, 1, N'LeaseScheduleテーブル')


CREATE PROCEDURE dbo.ap_LeasedAsset_Insert1
-- リース備品を挿入し、リーススケジュールの総額を更新する
-- 不完全なソリューションの例
(
    @intEqId INT,
    @intLocationId INT,
    @intStatusId INT,
    @intLeaseId INT,
    @intLeaseScheduleId INT,
    @intOwnerId INT,
    @mnyLease MONEY,
    @intAcquisitionTypeID INT
)
AS
    SET NOCOUNT ON

    BEGIN TRANSACTION

    -- 備品の挿入
    INSERT dbo.Inventory(
        EqId,
        LocationId,
        StatusId,
        LeaseId,
        LeaseScheduleId,
        OwnerId,
        Lease,
        AcquisitionTypeID
    )
    VALUES(
        @intEqId,
        @intLocationId,
        @intStatusId,
        @intLeaseId,
        @intLeaseScheduleId,
        @intOwnerId,
        @mnyLease,
        @intAcquisitionTypeID
    )

    -- 総額の更新
    UPDATE dbo.LeaseSchedule
    SET PeriodicTotalAmount = PeriodicTotalAmount + @mnyLease
    WHERE LeaseId = @intLeaseId

    COMMIT TRANSACTION
    RETURN

---------------------------------------------------------------------
-- 6.3 @@ERROR を使ったエラー処理
---------------------------------------------------------------------

CREATE PROCEDURE dbo.ap_LeasedAsset_Insert1
-- リース備品を挿入し、リーススケジュールの総額を更新する
-- まだ完璧とは言えないソリューションの例
(
    @intEqId INT,
    @intLocationId INT,
    @intStatusId INT,
    @intLeaseId INT,
    @intLeaseScheduleId INT,
    @intOwnerId INT,
    @mnyLease MONEY,
    @intAcquisitionTypeID INT
)
AS
    SET NOCOUNT ON

    BEGIN TRANSACTION
    -- 備品の挿入
    INSERT Inventory(
        EqId,
        LocationId,
        StatusId,
        LeaseId,
        LeaseScheduleId,
        OwnerId,
        Lease,
        AcquisitionTypeID
    )
    VALUES(
        @intEqId,
        @intLocationId,
        @intStatusId,
        @intLeaseId,
        @intLeaseScheduleId,
        @intOwnerId,
        @mnyLease,
        @intAcquisitionTypeID
    )

    IF @@ERROR <> 0
    BEGIN
        PRINT N'予期しないエラーが発生しました'
        ROLLBACK TRANSACTION
        RETURN 1
    END

    -- 総額の更新
    UPDATE LeaseSchedule
    SET PeriodicTotalAmount = PeriodicTotalAmount + @mnyLease
    WHERE LeaseId = @intLeaseId

    IF @@ERROR <> 0
    BEGIN
        PRINT N'予期しないエラーが発生しました'
        ROLLBACK TRANSACTION
        RETURN 1
    END

    COMMIT TRANSACTION
    RETURN 0

---------------------------------------------------------------------
-- 6.4 TRY...CATCH ステートメント
---------------------------------------------------------------------

CREATE PROCEDURE dbo.ap_ChargeLog_Insert
    @ItemId INT,
    @ActionId SMALLINT,
    @Cost MONEY,
    @Note VARCHAR(max),
    @Activity VARCHAR(1000)
AS
    BEGIN TRY
        INSERT ChargeLog(
            ItemId,
            ActionId,
            ChargeDate,
            Cost,
            Note
        )
        VALUES(
            @ItemId,
            @ActionId,
            GETDATE(),
            @Cost,
            @Note
        )

        INSERT INTO ActivityLog(
            Activity,
            LogDate,
            UserName,
            Note
        )
        VALUES(
            @Activity,
            GETDATE(),
            SYSTEM_USER,
            @Note
        )
    END TRY

    BEGIN CATCH
        INSERT INTO ErrorLog(
            ErrorNum,
            ErrorType,
            ErrorMsg,
            ErrorSource
        )
        VALUES(
            50000,
            'E',
            'Unable to record transaction in ChargeLog.',
            'ap_ChargeLog_Insert'
        )
    END CATCH

    RETURN


BEGIN TRY
    PRINT N'TRYブロック開始'
    INSERT ChargeLog(ItemId, ActionId, ChargeDate, Cost, Note)
    VALUES(30, 15, GETDATE(), $150, NULL)

    RAISERROR(N'エラーが発生しました!', 10, 1)

    INSERT INTO ActivityLog(Activity, LogDate, UserName, Note)
    VALUES('Repair', GETDATE(), SYSTEM_USER, NULL)
    PRINT N'TRYブロック終了'
END TRY

BEGIN CATCH
    PRINT N'CATCHブロック'
    INSERT INTO ErrorLog(ErrorNum, ErrorType, ErrorMsg, ErrorSource)
    VALUES(50000, 'E', 'Unable to record transaction in ChargeLog.',
        'ap_ChargeLog_Insert')
END CATCH

PRINT N'完了しました!'


BEGIN TRY
    PRINT N'TRYブロック開始'
    RAISERROR(N'エラーが発生しました!', 23, 1)
    PRINT N'TRYブロック終了'
END TRY

BEGIN CATCH
    PRINT N'CATCHブロック'
END CATCH

PRINT N'完了しました!'


PRINT N'開始'
RAISERROR(N'エラーが発生しました!', 23, 1) WITH LOG
IF @@ERROR <> 0
    PRINT N'エラーを検出しました'


DECLARE @i INT
PRINT N'開始'
SET @i = '2005/2/2'
IF @@ERROR <> 0
    PRINT N'エラーが発生しました!'
PRINT N'完了しました!'


BEGIN TRY
    PRINT N'TRYブロック開始'
    DECLARE @i INT
    SET @i = '2005/2/2'
    PRINT N'TRYブロック終了'
END TRY

BEGIN CATCH
    PRINT N'CATCHブロック'
END CATCH
PRINT N'完了しました!'


CREATE Procedure dbo.ap_ChargeLog_Insert2
    @ItemId INT,
    @ActionId SMALLINT,
    @Cost MONEY,
    @Note VARCHAR(max),
    @Activity VARCHAR(1000)
AS
    BEGIN TRY
        INSERT ChargeLog(
            ItemId,
            ActionId,
            ChargeDate,
            Cost,
            Note
        )
        VALUES(
            @ItemId,
            @ActionId,
            GETDATE(),
            @Cost,
            @Note
        )

        INSERT INTO ActivityLog(
            Activity,
            LogDate,
            UserName,
            Note
        )
        VALUES(
            @Activity,
            GETDATE(),
            SYSTEM_USER,
            @Note
        )
    END TRY

    BEGIN CATCH
        DECLARE @severity INT
        SET @severity = ERROR_SEVERITY()
        DECLARE @msg NVARCHAR(255)
        SET @msg = N'Unable to record transaction in ChargeLog.'
                 + N' Error(' + CAST(ERROR_NUMBER() AS NVARCHAR)
                 + N'):' + CAST(ERROR_MESSAGE() AS NVARCHAR)
                 + N' Severity = ' + CAST(ERROR_SEVERITY() AS NVARCHAR)
                 + N' State = ' + CAST(ERROR_STATE() AS NVARCHAR)
                 + N' Procedure = ' + CAST(ERROR_PROCEDURE() AS NVARCHAR)
                 + N' Line num. = ' + CAST(ERROR_LINE() AS NVARCHAR)

        INSERT INTO ErrorLog(
            ErrorNum,
            ErrorType,
            ErrorMsg,
            ErrorSource
        )
        VALUES(
            ERROR_NUMBER(),
            'E',
            @msg,
            ERROR_PROCEDURE()
        )

        RAISERROR (@msg, @severity, 2)
    END CATCH

    RETURN


CREATE PROCEDURE dbo.ap_ChargeLog_Insert_wTran
    @ItemId INT,
    @ActionId SMALLINT,
    @Cost MONEY,
    @Note VARCHAR(max),
    @Activity VARCHAR(1000)
AS
    BEGIN TRY
        BEGIN TRAN
        INSERT ChargeLog(
            ItemId,
            ActionId,
            ChargeDate,
            Cost,
            Note
        )
        VALUES(
            @ItemId,
            @ActionId,
            GETDATE(),
            @Cost,
            @Note
        )

        INSERT INTO ActivityLog(
            Activity,
            LogDate,
            UserName,
            Note
        )
        VALUES(
            @Activity,
            GETDATE(),
            SYSTEM_USER,
            @Note
        )
        COMMIT TRAN
    END TRY

    BEGIN CATCH
        ROLLBACK TRAN
        INSERT ErrorLog(
            ErrorNum,
            ErrorType,
            ErrorMsg,
            ErrorSource
        )
        VALUES(
            50000,
            'E',
            'Unable to record transaction in ChargeLog.',
            ERROR_PROCEDURE()
        )
    END CATCH

    RETURN


CREATE PROCEDURE dbo.ap_ChargeLog_Insert_wTranState
    @ItemId INT,
    @ActionId SMALLINT,
    @Cost MONEY,
    @Note VARCHAR(max),
    @Activity VARCHAR(1000)
AS
    DECLARE @Today SMALLDATETIME
    DECLARE @User SYSNAME
    DECLARE @ErrorCode INT
    DECLARE @EqId INT
    DECLARE @Price MONEY

    BEGIN TRY
        SELECT @Today = GETDATE()
        SET @User = SYSTEM_USER
        SET @ErrorCode = 0

        BEGIN TRAN
        INSERT ChargeLog(ItemId, ActionId, ChargeDate, Cost, Note)
        VALUES(@ItemId, @ActionId, @Today, @Cost, @Note)

        SELECT @EqId = EqId FROM dbo.OrderItem
        WHERE ItemId = @ItemId

        SELECT @Price = Price FROM dbo.PriceList
        WHERE EqId = @EqId

        INSERT INTO Sales(EqId, UnitPrice, Qty, ExtPrice, SalesDate)
        VALUES(@EqId, @Price, 1, @Price, @today)

        INSERT INTO ActivityLog(Activity, LogDate, UserName, Note)
        VALUES(@Activity, @Today , @User, @Note)

        COMMIT TRAN
    END TRY

    BEGIN CATCH
        SET @ErrorCode = ERROR_NUMBER()

        IF XACT_STATE() = -1
        -- トランザクションはコミットできない
        BEGIN
            ROLLBACK TRAN
            INSERT ErrorLog(
                ErrorNum,
                ErrorType,
                ErrorMsg,
                ErrorSource,
                ErrorState
            )
            VALUES(
                @ErrorCode,
                'E',
                'Unable to commit transaction.',
                ERROR_PROCEDURE(),
                -1
            )
        END

        ELSE IF XACT_STATE() = 0
        --トランザクション開始前にエラーが発生
        BEGIN
            INSERT ErrorLog(
                ErrorNum,
                ErrorType,
                ErrorMsg,
                ErrorSource,
                ErrorState
            )
            VALUES(
                @ErrorCode,
                'E',
                'Unable to pre-process transaction.',
                ERROR_PROCEDURE(),
                0
            )
        END

        ELSE IF XACT_STATE() = 1
        -- コミットとロールバックのいずれも可能
        BEGIN
            COMMIT TRAN
            IF NOT EXISTS(SELECT * FROM dbo.ChargeLog
                      WHERE ItemId = @ItemId
                      AND ChargeDate = @Today)
            BEGIN
                INSERT ErrorLog(
                    ErrorNum,
                    ErrorType,
                    ErrorMsg,
                    ErrorSource,
                    ErrorState
                )
                VALUES(
                    @ErrorCode,
                    'E',
                    'Unable to record transaction in ChargeLog.',
                    ERROR_PROCEDURE(),
                    1
                )
            END

            IF NOT EXISTS(SELECT * FROM dbo.Sales
                      WHERE EqId = @EqId
                      AND SalesDate = @Today)
            BEGIN
                INSERT ErrorLog(
                    ErrorNum,
                    ErrorType,
                    ErrorMsg,
                    ErrorSource,
                    ErrorState
                )
                VALUES(
                    @ErrorCode,
                    'E',
                    'Unable to record transaction in Sales.',
                    ERROR_PROCEDURE(),
                    1
                )
            END

            IF NOT EXISTS(SELECT * FROM dbo.ActivityLog
                      WHERE Activity = @Activity
                      AND LogDate = @Today
                      AND UserName = @User)
            BEGIN
                INSERT ErrorLog(
                    ErrorNum,
                    ErrorType,
                    ErrorMsg,
                    ErrorSource,
                    ErrorState
                )
                VALUES(
                    @ErrorCode,
                    'E',
                    'Unable to record transaction in ActivityLog.',
                    ERROR_PROCEDURE(),
                    1
                )
            END
        END
    END CATCH

    RETURN @ErrorCode


CREATE PROCEDURE dbo.ap_SalesByEqId_IncreasePrice
    @EqId INT,
    @Factor REAL
AS
    SET XACT_ABORT ON

    BEGIN TRAN
    UPDATE dbo.Sales
    SET UnitPrice = UnitPrice * @Factor,
        ExtPrice = ExtPrice * @Factor
    WHERE EqId = @EqId

    WAITFOR DELAY '0:00:10'

    UPDATE dbo.PriceList
    SET Price = Price * @Factor
    WHERE EqId = @EqId
    COMMIT TRAN
    RETURN

GO

CREATE PROCEDURE dbo.ap_PriceByEqId_Set
    @EqId INT,
    @Price MONEY
AS
    SET XACT_ABORT ON

    BEGIN TRAN
    UPDATE dbo.PriceList
    SET Price = @Price
    WHERE EqId = @EqId

    WAITFOR DELAY '0:00:10'

    UPDATE dbo.Sales
    SET UnitPrice = @Price,
        ExtPrice = @Price * Qty
    WHERE EqId = @EqId

    COMMIT TRAN
    RETURN


CREATE PROCEDURE dbo.ap_PriceByEqId_Set_wRetry
    @EqId INT,
    @Price MONEY
AS
    DECLARE @i INT
    SET @i = 1
    WHILE @i <= 10
    BEGIN
        BEGIN TRY
            SET XACT_ABORT ON

            BEGIN TRAN
            UPDATE dbo.PriceList
            SET Price = @Price
            WHERE EqId = @EqId

            WAITFOR DELAY '0:00:10'

            UPDATE dbo.Sales
            SET UnitPrice = @Price,
                ExtPrice = @Price * Qty
            WHERE EqId = @EqId
            COMMIT TRAN

            PRINT 'Completed!'
            BREAK
        END TRY

        BEGIN CATCH
            IF ERROR_NUMBER() = 1205
            BEGIN
                ROLLBACK TRAN
                SET @i = @i + 1
                PRINT 'retry'

                INSERT INTO ErrorLog(
                    ErrorNum,
                    ErrorType,
                    ErrorMsg,
                    ErrorSource,
                    CreatedBy,
                    CreateDT,
                    ErrorState
                )
                VALUES(
                    ERROR_NUMBER(),
                    'E',
                    ERROR_MESSAGE(),
                    ERROR_PROCEDURE(),
                    SUSER_SNAME(),
                    GETDATE(),
                    ERROR_STATE()
                )

                WAITFOR DELAY '0:00:03'
            END
        END CATCH
    END
    PRINT 'Completed!'
    RETURN

---------------------------------------------------------------------
-- 6.5 SET XACT_ABORT
---------------------------------------------------------------------

CREATE TABLE t_test(i INT)
GO

SET XACT_ABORT ON

BEGIN TRAN
PRINT N'開始'
INSERT t_test(i) VALUES(1)
INSERT t_test(i) VALUES('2007/5/5')
COMMIT TRAN
PRINT N'終了'
GO

SELECT * FROM t_test


SET XACT_ABORT ON
BEGIN TRY
    BEGIN TRAN
    PRINT N'TRYブロック開始'
    INSERT t_test(i) VALUES(1)
    INSERT t_test(i) VALUES('2007/5/5')
    COMMIT TRAN
    PRINT N'TRYブロック終了'
END TRY

BEGIN CATCH
    ROLLBACK TRAN
    PRINT N'CATCHブロック'
END CATCH

SELECT * FROM t_test


CREATE PROCEDURE dbo.ap_LeasedAsset_Insert7
-- リース備品を挿入し、リース料の総額を更新する
-- （SET XACT_ABORT ONを使ったソリューションの例）
(
    @intEqId INT,
    @intLocationId INT,
    @intStatusId INT,
    @intLeaseId INT,
    @intLeaseScheduleId INT,
    @intOwnerId INT,
    @mnyLease MONEY,
    @intAcquisitionTypeID INT
)
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON

    BEGIN TRANSACTION
    -- 備品の挿入
    INSERT Inventory(
        EqId,
        LocationId,
        StatusId,
        LeaseId,
        LeaseScheduleId,
        OwnerId,
        Lease,
        AcquisitionTypeID
    )
    VALUES(
        @intEqId,
        @intLocationId,
        @intStatusId,
        @intLeaseId,
        @intLeaseScheduleId,
        @intOwnerId,
        @mnyLease,
        @intAcquisitionTypeID
    )

    -- リース料の総額の更新
    UPDATE dbo.LeaseSchedule
    SET PeriodicTotalAmount = PeriodicTotalAmount + @mnyLease
    WHERE LeaseId = @intLeaseId
    COMMIT TRANSACTION

    RETURN (0)


CREATE PROCEDURE dbo.ap_Equipment_Insert
-- 備品のレコードを挿入する（必要に応じて備品の種類も挿入する）
-- （エラー処理およびトランザクション処理方法の代替例）
    @chvMake VARCHAR(50),
    @chvModel VARCHAR(50),
    @chvEqType VARCHAR(50),
    @intEqId INT OUTPUT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON
    DECLARE @intTrancountOnEntry INT,
            @intEqTypeId INT

    SET @intTrancountOnEntry = @@TRANCOUNT

    -- EqTypeテーブルに指定の備品の種類（EqType）が存在しなければ、それを挿入
    IF NOT EXISTS (SELECT EqTypeId FROM EqType
                   WHERE EqType = @chvEqType)
    BEGIN
        IF @@TRANCOUNT = 0
            BEGIN TRAN

        INSERT EqType(EqType)
        VALUES(@chvEqType)
        -- 挿入したEqTypeのIDを取得
        SELECT @intEqTypeId = @@IDENTITY
    END
    ELSE
    BEGIN
        -- 指定のEqTypeのIDを取得
        SELECT @intEqTypeId = EqTypeId
        FROM dbo.EqType
        WHERE EqType = @chvEqType
    END

    -- 備品を挿入
    INSERT dbo.Equipment(Make, Model, EqTypeId)
    VALUES(@chvMake, @chvModel, @intEqTypeId)

    SELECT @intEqId = @@IDENTITY

    IF @@TRANCOUNT > @intTrancountOnEntry
        COMMIT TRAN
    RETURN 0


CREATE PROCEDURE dbo.ap_Inventory_InsertXA
-- 備品レコードを挿入してそのIDを返し、さらにInventoryCountテーブルを更新する
-- （エラー処理およびトランザクション処理方法の代替例）
    @intEqId INT,
    @intLocationId INT,
    @inyStatusId TINYINT,
    @intLeaseId INT,
    @intLeaseScheduleId INT,
    @intOwnerId INT,
    @mnsRent SMALLMONEY,
    @mnsLease SMALLMONEY,
    @mnsCost SMALLMONEY,
    @inyAcquisitionTypeID INT,
    @intInventoryId INT OUTPUT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON
    DECLARE @intTrancountOnEntry INT
    SET @intTrancountOnEntry = @@TRANCOUNT

    IF @@TRANCOUNT = 0
        BEGIN TRAN

    INSERT INTO dbo.Inventory(
        EqId,
        LocationId,
        StatusId,
        LeaseId,
        LeaseScheduleId,
        OwnerId,
        Rent,
        Lease,
        Cost,
        AcquisitionTypeID
    )
    VALUES(
        @intEqId,
        @intLocationId,
        @inyStatusId,
        @intLeaseId,
        @intLeaseScheduleId,
        @intOwnerId,
        @mnsRent,
        @mnsLease,
        @mnsCost,
        @inyAcquisitionTypeID
    )

    SELECT @intInventoryId = SCOPE_IDENTITY()

    UPDATE InventoryCount
    SET InvCount = InvCount + 1
    WHERE LocationId = @intLocationId

    IF @@ROWCOUNT <> 1
    BEGIN
        -- ビジネスロジックのエラー
        RAISERROR(50133, 16, 1)
        IF @@TRANCOUNT > @intTrancountOnEntry
            ROLLBACK TRAN
        RETURN 50133
    END

    IF @@TRANCOUNT > @intTrancountOnEntry
        COMMIT TRAN
    RETURN 0


CREATE PROCEDURE dbo.ap_InventoryEquipment_Insert_XA
-- 新規の在庫および備品のレコードを挿入する
-- （エラー処理およびトランザクション処理方法の代替例）
    @chvMake VARCHAR(50),
    @chvModel VARCHAR(50),
    @chvEqType VARCHAR(30),
    @intLocationId INT,
    @inyStatusId TINYINT,
    @intLeaseId INT,
    @intLeaseScheduleId INT,
    @intOwnerId INT,
    @mnsRent SMALLMONEY,
    @mnsLease SMALLMONEY,
    @mnsCost SMALLMONEY,
    @inyAcquisitionTypeID INT,
    @intInventoryId INT OUTPUT,
    @intEqId INT OUTPUT
AS
    SET NOCOUNT ON
    SET XACT_ABORT ON

    DECLARE @intError INT,
            @intTrancountOnEntry INT

    SET @intError = 0
    SET @intTrancountOnEntry = @@TRANCOUNT

    IF @@TRANCOUNT = 0
        BEGIN TRAN

    -- データベースに既に存在する備品か
    IF NOT EXISTS(SELECT EqId
                  FROM Equipment
                  WHERE Make = @chvMake
                  AND Model = @chvModel)
        EXEC @intError = dbo.ap_Equipment_Insert
                            @chvMake,
                            @chvModel,
                            @chvEqType,
                            @intEqId OUTPUT

    IF @intError > 0
    BEGIN
        IF @@TRANCOUNT > @intTrancountOnEntry
            ROLLBACK TRAN
        RETURN @intError
    END

    EXEC @intError = dbo.ap_Inventory_InsertXA
                        @intEqId,
                        @intLocationId,
                        @inyStatusId,
                        @intLeaseId,
                        @intLeaseScheduleId,
                        @intOwnerId,
                        @mnsRent,
                        @mnsLease,
                        @mnsCost,
                        @inyAcquisitionTypeID,
                        @intInventoryId OUTPUT

    IF @intError > 0
    BEGIN
        IF @@TRANCOUNT > @intTrancountOnEntry
            ROLLBACK TRAN
        RETURN @intError
    END

    IF @@TRANCOUNT > @intTrancountOnEntry
        COMMIT TRAN
    RETURN 0


DECLARE @intError INT,
        @intInvId INT,
        @intEqId INT
BEGIN TRAN

EXEC @intError = ap_InventoryEquipment_Insert_XA
     @chvMake = 'Compaq',
     @chvModel = 'IPaq 3835',
     @chvEqType = 'PDA',
     @intLocationId = 12,
     @inyStatusId = 1,
     @intLeaseId = null,
     @intLeaseScheduleId = 1,
     @intOwnerId = 411,
     @mnsRent = null,
     @mnsLease = null,
     @mnsCost = $650,
     @inyAcquisitionTypeID = 1,
     @intInventoryId = @intInvId OUTPUT,
     @intEqId = @intEqId OUTPUT

IF @intError = 0
    COMMIT TRAN
ELSE
    ROLLBACK TRAN

SELECT @intError Err
SELECT * FROM Inventory WHERE InventoryId = @intInvId
SELECT * FROM Equipment WHERE EqId = @intEqId

