SQL Server 2000存储Proc爆炸没有明显的原因

时间:2011-03-25 17:11:46

标签: sql stored-procedures sql-server-2000

如果它总是炸弹或有些错误 - 任何帮助都会非常感激。

CREATE PROCEDURE sp_LetsWork
  (@MYID int,  @ThisDate Datetime)
AS
  SET NOCOUNT ON

  DECLARE @intErrorCode int,  
          @QStartDate datetime, 
          @QEndDate datetime 

  SELECT @intErrorCode = @@ERROR

  --DATEPART(mm, @ThisDate) BETWEEN  1 and 3 -- test both options
  BEGIN
    IF @ThisDate BETWEEN '01/01/' + CONVERT(VARCHAR(4), YEAR(@ThisDate)) 
                         AND '03/31/' + CONVERT(VARCHAR(4), YEAR(@ThisDate))  
    RunQuarter:
        SELECT * 
        FROM qryAR 
        WHERE CID = @MYID 
          AND (paiddate >= @QStartDate 
          AND paiddate <= @QEndDate)
        --ORDER BY paiddate ASC

        GO
        -- GOTO RunQuarter
  END
  GO

  SELECT @intErrorCode = @@ERROR

  IF (@intErrorCode <> 0) GOTO ErrHandler

  RETURN 0

ErrHandler:

  RETURN @intErrorCode

GO  

1 个答案:

答案 0 :(得分:7)

你在存储过程中有一个GO

GO不是SQL:它告诉SSMS等客户端工具批处理结束

因此 paiddate <=@QEndDate)之后的错误是,因为GO因为这是存储过程的结束:{{{}没有匹配END 1}}高于此

执行时不是“轰炸”,因为它没有被创建......