【问题标题】:Invalid object name when executing procedure执行过程时对象名称无效
【发布时间】:2015-04-13 08:01:22
【问题描述】:

我创建了这个程序:

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'

我收到此错误:

消息 208,级别 16,状态 1,过程 CashBook,第 8 行
对象名称“事务”无效。

Transactions存在

编辑

大多数评论者都在询问sp是否在同一个dm中fms,请看下图

【问题讨论】:

  • 你能进入创建SP的同一个数据库并运行SELECT * FROM fms.dbo.Transactions
  • fms.dbo.Transactions 这个名字对吗?
  • @AmeyaDeshpande 我在管理工作室本地破坏数据库是fms 表是Transactions
  • @Nick.McDermaid 是的,它有效,请参阅我上面的评论
  • 您可以使用单个查询插入数据吗?使用此查询INSERT INTO @runningTable (TransDate,Credit,Debit, Balance) VALUES (@startDate, NULL, NULL, @openingBalance);

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


【解决方案1】:

也许它被缓存了,试试这个方法,让我们知道它是否有效。

SQL 管理→ 编辑 → IntelliSense → 刷新本地缓存

【讨论】:

  • 嗨,史密斯,你能执行 Select * from fms.dbo.Transactions 吗?
  • 我认为是因为dbo的权限
【解决方案2】:

我发现了错误

我仔细检查了数据库,发现我错误地在主表中创建了那个cashbook过程,所以我把它删除了

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-19
    • 2023-04-11
    相关资源
    最近更新 更多