执行过程时无效的对象名称

时间:2015-04-13 08:01:22

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

我创建了这个程序:

CREATE Procedure CashBook (@startDate DateTime, @endDate DateTime)
AS
BEGIN
   Declare @runningTable TABLE(TransDate DateTime, Debit Money, Credit Money, Balance Money)
   Declare @closingBalance Money, @runningBalance Money, @openingBalance Money
   --Get the opening Balance on the date you want to start at
   SELECT  
       @openingBalance = SUM(coalesce(credit, 0) - coalesce(debit, 0)) 
   FROM
       fms.dbo.Transactions 
   WHERE 
       DataSource IN (4, 3) AND TransDate <  @startDate;

   --Now do the rest
   INSERT INTO @runningTable (TransDate, Credit, Debit, Balance) 
   VALUES (@startDate, NULL, NULL, @openingBalance);

   SELECT @runningBalance = @openingBalance;

   INSERT INTO @runningTable (TransDate, Credit, Debit, Balance) 
      SELECT 
          TransDate, Credit, Debit,
          (coalesce(credit, 0) - coalesce(debit, 0)) AS Balance 
      FROM 
          fms.dbo.Transactions 
      WHERE 
          TransDate BETWEEN @startDate AND @endDate;

  --Calculate the Running Balance
  SELECT  
      @closingBalance = SUM(coalesce(credit, 0) - coalesce(debit, 0)) 
  FROM
      fms.dbo.Transactions 
  WHERE 
      DataSource IN (4, 3) AND TransDate <  @endDate

  --Now do the rest
  INSERT INTO @runningTable (TransDate, Credit, Debit, Balance) 
  VALUES (@endDate, NULL, NULL, @closingBalance)

  --Calculate the Running Balance
  SELECT * FROM @runningTable
END

当我在Management Studio中执行时,通过调用

cashbook '2014-02-01', '2014-02-01'

我收到此错误:

  

Msg 208,Level 16,State 1,Procedure CashBook,Line 8
  无效的对象名称&#39;交易&#39;。

Transactions存在

修改

大多数评论者都在询问sp是否在同一个fms,请参阅下面的图片

sp

1 个答案:

答案 0 :(得分:0)

我找到了错误

我在数据库中进行了彻底的检查,发现我在主表中错误地创建了现金手册,所以我将其删除了

但我不知道为什么这会干扰另一个数据库中的现金簿