LN_REF_NO
貸出の照会番号です。LN_REF_NO
1 つの ACNO と 1 つの LRAC が必要です。
両方とも ACNO COLUMN の下のアカウントに保存されます。
どうすればそれらを分離できますか? Pls は画像を見て
ALTER PROCEDURE sp_FinalLoanPayment
AS
DECLARE @LN_REF_NO char(13)
DECLARE @TempA
TABLE (
[LN_REF_NO] [char](13),
[Status] [varchar](15),
[ACNO] [varchar](21),
[ACNOBalance] [dbo].[Amount]
)
DECLARE @TempL
TABLE (
[LN_REF_NO] [char](13),
[Status] [varchar](15),
[LRAC] [varchar](21),
[LRACBalance] [dbo].[Amount]
)
DECLARE @TempAll
TABLE (
[LN_REF_NO] [char](13),
[Status] [varchar](15),
[ACNO] [varchar](21),
[ACNOBalance] [dbo].[Amount],
[LRAC] [varchar](21),
[LRACBalance] [dbo].[Amount]
)
INSERT INTO @TempL (LN_REF_NO ,Status,LRAC,LRACBalance)
SELECT Loan.LN_REF_NO, Loan.Status,ACCOUNTS.ACNO ,ACCOUNTS.BALANCE
FROM Loan
INNER JOIN Accounts
ON LOAN.LRAC = ACCOUNTS.ACNO
WHERE Loan.Status ='Paid' AND ACCOUNTS.BALANCE>0
INSERT INTO @TempA (LN_REF_NO ,Status,ACNO,ACNOBalance)
SELECT Loan.LN_REF_NO, Loan.Status,ACCOUNTS.ACNO ,ACCOUNTS.BALANCE
FROM Loan
INNER JOIN Accounts
ON LOAN.ACNO = ACCOUNTS.ACNO
WHERE Loan.Status ='Paid' AND ACCOUNTS.BALANCE<0
-- START CURSOR 1
DECLARE @cursor CURSOR
SET @cursor = CURSOR FOR
select LN_REF_NO from @TempL
OPEN @cursor
FETCH NEXT
FROM @cursor INTO
@LN_REF_NO
WHILE (@@FETCH_STATUS = 0)
BEGIN
INSERT INTO @TempAll (LN_REF_NO ,Status,ACNO,ACNOBalance)
select LN_REF_NO,Status,ACNO,ACNOBalance
from @TempA
where LN_REF_NO = @LN_REF_NO
FETCH NEXT
FROM @cursor INTO
@LN_REF_NO
END
CLOSE @cursor
DEALLOCATE @cursor
-- CURSOR 1 END
select * from @TempAll order by LN_REF_NO
結果: