数据未显示在存储过程中

时间:2014-08-18 01:45:43

标签: sql sql-server stored-procedures

我是新来的,请错误地纠正我。

我执行了此存储过程,但是,当我执行它时,只有ErrorNumberSPNameErrorMessage出现。

有人可以向我解释我做错了什么吗?感谢。

这就是我执行的内容:

exec dbo.spPartMasterExtension @DomainSite = 'BRIS0011', @ItemNo='1002424251911',
                               @ItemDescription = 'New Item', @ItemValue = '1',
                               @ItemUM = '1', @EmployeeNo = 'nn031097'

这是存储过程:

CREATE PROCEDURE [dbo].[spPartMasterExtension]
   @DomainSite nvarchar(8),
   @ItemNo nvarchar(18),
   @ItemDescription nvarchar(50),
   @ItemValue nvarchar(50),
   @ItemUM nvarchar(50),
   @EmployeeNo nvarchar(18)
AS
BEGIN
   Declare @ErrorNo integer = '',
           @SPName nvarchar(max) = '',
           @ErrorMessage nvarchar(max) = ''
  Declare @ItemUMOriginal nvarchar(50)

  IF EXISTS (SELECT ID FROM PartMasterExtension 
             WHERE ItemNo = @ItemNo and ItemDescription = @ItemDescription and DomainSite =@DomainSite)
  BEGIN
      UPDATE PartMasterExtension 
      SET ItemValue = @ItemValue, 
          ItemUM = @ItemUM,
          DateTimeStamp = GETDATE(),
          EmployeeNo = @EmployeeNo 
      WHERE 
          ItemNo = @ItemNo AND ItemDescription = @ItemDescription AND DomainSite = @DomainSite 
  END
  ELSE 
  BEGIN
    BEGIN TRY
        INSERT INTO PartMasterExtension
           SELECT 
               @DomainSite, @ItemNo, @ItemDescription,
               @ItemValue, @ItemUM, getdate(), @EmployeeNo
    END TRY
    BEGIN CATCH
         SELECT 
            @ErrorNo = ERROR_NUMBER(),
            @SPName = ERROR_PROCEDURE(),
            @ErrorMessage = ERROR_MESSAGE();
    END CATCH
  END

  SELECT 
    @ErrorNo as ErrorNumber,
    @SPName as SPName, 
    @ErrorMessage AS ErrorMessage;
END
GO

1 个答案:

答案 0 :(得分:0)

如果产品已存在,则更新将处理,然后是您的最后一个SELECT。如果数据不存在,它将尝试插入数据,如果发生错误,将在返回之前将值设置为您声明的变量。

您对存储过程有何期待?