简体   繁体   English

执行过程时对象名称无效

[英]Invalid object name when executing procedure

I created this procedure: 我创建了以下过程:

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

When I execute it in Management Studio, by calling 当我在Management Studio中执行时,通过调用

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

I get this error: 我收到此错误:

Msg 208, Level 16, State 1, Procedure CashBook, Line 8 消息208,层16,状态1,程序CashBook,第8行
Invalid object name 'Transactions'. 无效的对象名称“交易”。

The table Transactions exists Transactions存在

EDIT 编辑

Most commenter are asking if the sp is in the same dm fms , please see the image below 大多数评论者都在询问sp是否在相同的dm fms ,请参见下图

SP

Maybe it's cached ,try this way and let us know if it work. 也许它已被缓存,请尝试这种方式,让我们知道它是否有效。

SQL Managenemt→ Edit → IntelliSense → Refresh Local Cache SQL Managenemt→编辑→IntelliSense→刷新本地缓存

在此处输入图片说明

I found the bug 我发现了错误

I did thorough check in the database and found that I mistakenly created that cashbook procedure in the master table, so I deleted it 我对数据库进行了彻底检查,发现我在主表中错误地创建了该现金簿程序,因此我将其删除

I don't however know why this should interfere with the cashbook in another database 但是,我不知道为什么这会干扰另一个数据库中的现金簿

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM