将表中的内容复制到存储过程中以进行备份和存储

时间:2013-04-05 05:36:45

标签: sql stored-procedures backup

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

我需要做的是将员工信息移动到存档和备份的存档表,当员工编号不存在时提高错误消息,并且只移动没有销售的员工记录,目前我被困在什么上在我确定销售号码和员工编号都不为空之后。 以下是我到目前为止的情况:

        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

1 个答案:

答案 0 :(得分: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

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