过于SQL存储过程求解!
IF EXISTS (
SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
WHERE SPECIFIC_SCHEMA = N'CustmerDetails'
AND SPECIFIC_NAME = N'apf_CustBalances'
)
DROP PROCEDURE CustmerDetails.apf_CustBalances
GO
CREATE PROCEDURE CustmerDetails.apf_CustBalances
@CustId int,
@ClearedBalance money OUTPUT, @UnclearedBalance money OUTPUT
AS
SELECT @ClearedBalance = ClearedBalance, @UnclearedBalance = UnclearedBalance
FROM Customers
WHERE CustomerId = @CustId
Return @@Error
GO
消息 2760,级别 16,状态 1,过程 apf_CustBalances,第 11 行
指定的架构名称 "CustmerDetails" 不存在,或者您没有使用该名称的权限。
我有这个架构啊!!!为什么为什么
SQL
[解决办法]
比较恶心的改法,分开来写
CREATE PROCEDURE CustomerDetails.apf_CustMovement @CustId bigint,
@FromDate datetime, @ToDate datetime
AS
BEGIN
DECLARE @RunningBal money, @StillCalc Bit, @LastTran bigint
SELECT @StillCalc = 1, @LastTran = 0, @RunningBal = 0
WHILE @StillCalc = 1
BEGIN
SELECT TOP 1 @LastTran = t.TransactionId
FROM CustomerDetails.Customers c
JOIN TransactionDetails.Transactions t ON t.CustomerId = c.CustomerId
JOIN TransactionDetails.TransactionTypes tt ON
tt.TransactionTypeId = t.TransactionType
WHERE t.TransactionId > @LastTran
AND tt.AffectCashBalance = 1
AND DateEntered BETWEEN convert(varchar(30),@FromDate,121) AND convert(varchar(30),@ToDate,121)
--AND Date Between convert(varchar(30),@FromDate,121) AND convert(varchar(30),Todate,121)
ORDER BY DateEntered
SELECT TOP 1 @RunningBal + CASE
WHEN tt.CreditType = 1 THEN t.Amount
ELSE t.Amount * -1 END
FROM CustomerDetails.Customers c
JOIN TransactionDetails.Transactions t ON t.CustomerId = c.CustomerId
JOIN TransactionDetails.TransactionTypes tt ON
tt.TransactionTypeId = t.TransactionType
WHERE t.TransactionId > @LastTran
AND tt.AffectCashBalance = 1
AND DateEntered BETWEEN convert(varchar(30),@FromDate,121) AND convert(varchar(30),@ToDate,121)
--AND Date Between convert(varchar(30),@FromDate,121) AND convert(varchar(30),Todate,121)
ORDER BY DateEntered
IF @@ROWCOUNT > 0
--Perform some interest calculation here...
CONTINUE
ELSE
BREAK
END
SELECT @RunningBal AS 'End Balance'
END
GO