Northwind Database (Document! X Sample)
HumanResources.uspUpdateEmployeeHireInfo Stored Procedure
AdventureWorks Database > HumanResources Schema : HumanResources.uspUpdateEmployeeHireInfo Stored Procedure
Description
Updates the Employee table and inserts a new row in the EmployeePayHistory table with the values specified in the input parameters.
Properties
Creation Date27/10/2017 14:33
Encrypted
Ansi Nulls
Parameters
ParameterDirectionDescriptionData TypeSize
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter a valid BusinessEntityID from the Employee table.Integer4
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter a title for the employee.VarWChar50
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter a hire date for the employee.DBTimeStamp4
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter the date the rate changed for the employee.DBTimeStamp4
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter the new rate for the employee.Currency8
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter the pay frequency for the employee.UnsignedTinyInt1
InInput parameter for the stored procedure uspUpdateEmployeeHireInfo. Enter the current flag for the employee.dbo.Flag1
Return Value Integer4
Objects that HumanResources.uspUpdateEmployeeHireInfo depends on
 Database ObjectObject TypeDescriptionDep Level
Person.BusinessEntity tablePerson.BusinessEntityTableSource of the ID that connects vendors, customers, and employees with address and contact information.3
HumanResources.Employee tableHumanResources.EmployeeTableEmployee information such as salary, department, and title.1
HumanResources.EmployeePayHistory tableHumanResources.EmployeePayHistoryTableEmployee pay history.1
dbo.ErrorLog tabledbo.ErrorLogTableAudit table tracking errors in the the AdventureWorks database that are caught by the CATCH block of a TRY...CATCH construct. Data is inserted by stored procedure dbo.uspLogError when it is executed from inside the CATCH block of a TRY...CATCH construct.2
dbo.Flag datatypedbo.FlagUser Defined Data Type 1
dbo.Name datatypedbo.NameUser Defined Data Type 3
dbo.NameStyle datatypedbo.NameStyleUser Defined Data Type 3
Person.Person tablePerson.PersonTableHuman beings involved with AdventureWorks: employees, customer contacts, and vendor contacts.2
dbo.uspLogError proceduredbo.uspLogErrorStored ProcedureLogs error information in the ErrorLog table about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without inserting error information.1
dbo.uspPrintError proceduredbo.uspPrintErrorStored ProcedurePrints error information about the error that caused execution to jump to the CATCH block of a TRY...CATCH construct. Should be executed from within the scope of a CATCH block otherwise it will return without printing any error information.2
Procedure Source Code
CREATE PROCEDURE [HumanResources].[uspUpdateEmployeeHireInfo]
    @BusinessEntityID [int], 
    @JobTitle [nvarchar](50), 
    @HireDate [datetime], 
    @RateChangeDate [datetime], 
    @Rate [money], 
    @PayFrequency [tinyint], 
    @CurrentFlag [dbo].[Flag] 
WITH EXECUTE AS CALLER
AS

BEGIN
    SET NOCOUNT ON;

    BEGIN TRY
        BEGIN TRANSACTION;

        UPDATE [HumanResources].[Employee] 
        SET [JobTitle] = @JobTitle 
            ,[HireDate] = @HireDate 
            ,[CurrentFlag] = @CurrentFlag 
        WHERE [BusinessEntityID] = @BusinessEntityID;

        INSERT INTO [HumanResources].[EmployeePayHistory] 
            ([BusinessEntityID]
            ,[RateChangeDate]
            ,[Rate]
            ,[PayFrequency]) 
        VALUES (@BusinessEntityID, @RateChangeDate, @Rate, @PayFrequency);

        COMMIT TRANSACTION;
    END TRY
    BEGIN CATCH
        -- Rollback any active or uncommittable transactions before
        -- inserting information in the ErrorLog
        IF @@TRANCOUNT > 0
        BEGIN
            ROLLBACK TRANSACTION;
        END

        EXECUTE [dbo].[uspLogError];
    END CATCH;
END;
See Also

Related Objects

HumanResources Schema
AdventureWorks Database