执行过程时对象名称无效
Invalid object name when executing 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
当我在 Management Studio 中执行它时,通过调用
cashbook '2014-02-01', '2014-02-01'
我收到这个错误:
Msg 208, Level 16, State 1, Procedure CashBook, Line 8
Invalid object name 'Transactions'.
table Transactions
存在
编辑
大多数评论者都在问 sp
是否在同一个 dm fms
中,请看下图
也许它被缓存了,试试这个方法,如果有效请告诉我们。
SQL 管理→编辑→智能感知→刷新本地缓存
我发现了错误
我查了下数据库,发现是我在mastertable里面错误地创建了那个cashbook程序,所以我删除了它
但是我不知道为什么这会干扰另一个数据库中的现金簿
我创建了这个程序:
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
Invalid object name 'Transactions'.
table Transactions
存在
编辑
大多数评论者都在问 sp
是否在同一个 dm fms
中,请看下图
也许它被缓存了,试试这个方法,如果有效请告诉我们。
SQL 管理→编辑→智能感知→刷新本地缓存
我发现了错误
我查了下数据库,发现是我在mastertable里面错误地创建了那个cashbook程序,所以我删除了它
但是我不知道为什么这会干扰另一个数据库中的现金簿