Untitled

mail@pastecode.io avatar
unknown
sqlserver
15 days ago
1.1 kB
2
Indexable
Never
USE [HRDBVA04]
GO
/****** Object:  StoredProcedure [dbo].[sp_ImportLast12MonthBalanceSalary]    Script Date: 02.09.2024 10:52:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER   PROCEDURE [dbo].[sp_ImportLast12MonthBalanceSalary]
    @finCode NVARCHAR(7),
    @month INT,
    @year INT,
    @salary FLOAT
AS
BEGIN
    DECLARE @empId INT = (SELECT ID FROM HR_EMPLOYEES WHERE FIN_CODE = @finCode)
    IF EXISTS
    (
        SELECT 1
        FROM HR_LAST_12_MONTH_BALANCE_SALARY
        WHERE MONTH_ = @month
              AND YEAR_ = @year
              AND EMP_ID = @empId
    )
    BEGIN
        UPDATE HR_LAST_12_MONTH_BALANCE_SALARY
        SET MONTH_ = @month,
            YEAR_ = @year,
            SALARY = @salary
        WHERE EMP_ID = @empId
    END
    ELSE
    BEGIN
        INSERT INTO HR_LAST_12_MONTH_BALANCE_SALARY
        (
            EMP_ID,
            MONTH_,
            YEAR_,
            SALARY
        )
        VALUES
        (@empId, @month, @year, @salary)
    END
END
Leave a Comment