存储过程中附近的语法不正确

时间:2014-12-24 08:54:03

标签: sql-server-2008 stored-procedures

我创建了一个存储过程。我想执行它时出错。消息是

  

@ErrorMessage附近的语法不正确。

此存储过程中出错了什么?

ALTER procedure  [dbo].[CWPAYROLL_REVERSE] 
   @TRANID integer,
   @CALLDUE tinyint,
   @SETRDATE tinyint,
   @OUTTRANID integer out,
   @ErrorMessage varchar(4000) out  
As      
begin      
   declare @TRANTYPE char(5);      
   declare @TAXTRANID integer;      
   declare @OUTTAXTRANID integer;      
   declare @UNFINNAME char(5);      
   declare @REVERSENAME char(5);      
   declare @DRIVERID integer;

   BEGIN TRY
   BEGIN TRANSACTION
      SELECT
          @DRIVERID = DRIVERID,
          @TRANTYPE = TRANTYPE,
          @TAXTRANID = TAXTRANID   
      FROM
          PAYROLL 
      WHERE
          TRANID = @TRANID;      

      SELECT
          @UNFINNAME = UNFINNAME,
          @REVERSENAME = REVERSENAME  
      FROM 
          PAYROLLTRANTYPES 
      WHERE 
          TRANTYPE = @TRANTYPE;      

      IF (@UNFINNAME is null) or (@REVERSENAME is null)
      BEGIN 
            --raiserror 23000 'UNFINALIZED OR REVERSE TRAN TYPES ARE BLANK'      
    @ErrorMessage = 'UNFINALIZED OR REVERSE TRAN TYPES ARE BLANK' // Getting error in this line 
            return

      END 
    if(@TAXTRANID is not null)        
        exec CWPAYROLL_REVERSE @TAXTRANID,0,0,@OUTTAXTRANID output ,@ErrorMessage output      
    else      
        set @OUTTAXTRANID=null      

        exec GETNEWRECID2 'PAYROLL','TRANID','PAYROLL',@OUTTRANID  output      
        SELECT @OUTTRANID AS NEWTRANTYPE     
      insert into  PAYROLL(TRANID,TRANTYPE,DRIVERID,TRANDESC,TRANDATE,AMOUNT,PAID,TAXTRANID)      
        select @OUTTRANID,@REVERSENAME,DRIVERID,'REVERSE FOR '+TRANDESC,      
          TRANDATE,-AMOUNT,1,@OUTTAXTRANID from      
           PAYROLL where      
          TRANID = @TRANID;     

    update  PAYROLL set TRANTYPE = @UNFINNAME,PAID = 1 where TRANID = @TRANID;      
    if @CALLDUE = 1        
         exec PAYROLL_SETDUE @DRIVERID,@SETRDATE   
     COMMIT TRANSACTION
   END TRY
   BEGIN CATCH 
        ROLLBACK TRANSACTION
         --SELECT  @ErrorMessage  = ERROR_MESSAGE()  
            RAISERROR  23000  @ErrorMessage  
   END CATCH
END 

2 个答案:

答案 0 :(得分:1)

你不能像这样直接打电话

@ErrorMessage = 'UNFINALIZED OR REVERSE TRAN TYPES ARE BLANK' 

应该是

Set @ErrorMessage = 'UNFINALIZED OR REVERSE TRAN TYPES ARE BLANK'; 

答案 1 :(得分:0)

SET @ErrorMessage = 'UNFINALIZED OR REVERSE TRAN TYPES ARE BLANK'