I have a view i have created that im trying to select into a coloumn the previous TransactionDate of a loan. How can i do this all in the same view.
EXAMPLE
LOAN TranDate PrevTranDate
0001 1/1/07 null
0001 1/2/07 1/1/07
0002 1/4/07 null
0001 1/5/07 1/2/07
EXAMPLE
LOAN TranDate PrevTranDate
0001 1/1/07 null
0001 1/2/07 1/1/07
0002 1/4/07 null
0001 1/5/07 1/2/07
Code:
SELECT
CC.AutoID,
H.LoanID,
H.HistoryCounter,
H.SysDateTime,
IsNUll( CC_Orig.DateAdded,CC.DateAdded ) As DateAdded,
IsNULL(CC_Orig.EndDate, CC.EndDate) As EndDate,
IsNULL( CC_Orig.CollectorCode, CC.CollectorCode) As CollectorCode,
IsNULL(CC_Orig.CollectorName,CC.CollectorName) As CollectorName,
H.TransactionCode,
H.TransactionAmt,
TransactionCode.Description AS TranCodeDesc,
H.TransactionDate,
H.ReversalCode,
H.ReversalFlag,
Status.Legal,
S_ReversalCode.Description AS ReversalCodeDesc,
S_ReversalFlag.Description AS ReversalFlagDesc,
H.MoneyType,
Company.Name1,
S_MoneyType.Description AS MoneyTypeDesc,
Status.PrimStat
/*
CC.DateAdded As DateAdded1,
CC.EndDate As EndDate1,
CC.CollectorCode As CollectorCode1,
CC.CollectorName As CollectorName1
*/
FROM Company,
CollectorCodeHistory CC
INNER JOIN History H
ON ( CC.LoanID = H.LoanID
AND CC.DateAdded <= H.SysDateTime
AND ISNULL(CC.EndDate, GetDate()) >= H.SysDateTime
AND H.TransactionCode BETWEEN 100 and 340 AND TransactionCode <> 140 AND TransactionAmt <> 0 )
LEFT JOIN CorrectedHistory CH ON ( H.HistoryCounter = CH.HistoryCounterReversal AND H.LoanID = CH.LoanID )
LEFT JOIN CollectorCodeHistory CC_Orig
ON ( CC_Orig.LoanID = CH.LoanID
AND CC_Orig.DateAdded <= CH.SysDateTime
AND ISNULL(CC_Orig.EndDate, GetDate()) >= CH.SysDateTime )
INNER JOIN Status ON H.LoanID = Status.LoanID
INNER JOIN TransactionCode ON H.TransactionCode = TransactionCode.Code
INNER JOIN S_ReversalFlag ON H.ReversalFlag = S_ReversalFlag.Code
INNER JOIN S_ReversalCode ON H.ReversalCode = S_ReversalCode.Code
INNER JOIN S_MoneyType ON H.MoneyType = S_MoneyType.Code
Where H.MoneyType <> 0