0

我有一个关于引发错误并将表中的内容复制到存储过程中的问题。

我需要做的是将员工信息移动到存档表进行存储和备份,当员工编号不存在时引发错误消息,并且只移动没有销售的员工记录,目前我被困在我之后该怎么办'确保销售编号和员工编号都不为空。这是我到目前为止所拥有的:

        Create Procedure ArchiveEmployeeTranactions 
        (
        @SaleNumber int,
        @EmployeeNumber int
        )
        AS
        SELECT     sale.employeeNumber, employee.FirstName, employee.LastName, sale.saleNumber
        FROM         employee INNER JOIN
                              sale ON employee.EmployeeNumber = sale.employeeNumber

                            IF @SaleNumber is null 
                            BEGIN
                            RAISERROR ('Please enter valid Sale Number',16,1) 
                            END

                            Else
                            BEGIN
                            IF @EmployeeNumber is null
                            RAISERROR ('Please enter Valid Employee Number',16,1)
                            END
4

1 回答 1

0


 Create Procedure ArchiveEmployeeTranactions 
        (
           @SaleNumber int,
           @EmployeeNumber int
        )
  AS
  BEGIN
        IF @SaleNumber is null 
        BEGIN
           RAISERROR ('Please enter valid Sale Number',16,1) 
        END

    Else IF @EmployeeNumber is null
       RAISERROR ('Please enter Valid Employee Number',16,1)
    END

    INSERT INTO Archive
    SELECT     sale.employeeNumber, 
               employee.FirstName, 
               employee.LastName, 
               sale.saleNumber
    FROM  employee 
    INNER JOIN sale 
    ON employee.EmployeeNumber = sale.employeeNumber
    WHERE employee.employeeNumber=@EmployeeNumber 
      and sale.saleNumber=@SaleNumber

END

于 2013-04-05T06:20:20.277 回答