Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1.  
  2. DECLARE
  3. @BookingID varchar(32) = 'IR0000002496',
  4.  
  5. @Date datetime = '20170110',
  6.  
  7. @LastDate datetime = '20170109',
  8.  
  9. @Value float
  10.  
  11. begin
  12.  
  13. declare @Ticket varchar(10),
  14.  
  15. @DueDate datetime,
  16.  
  17. @Cashflow int,
  18.  
  19. @ValueDate datetime,
  20. @PrincipalStart float
  21.  
  22. select @Ticket = Ticket from GL_Transaction where BookingID = @BookingId
  23.  
  24.  
  25.  
  26. select @Cashflow = Cashflow from IR_Deal where Ticket = @Ticket
  27.  
  28.  
  29. select @DueDate = max(InterestDate) from v_Cashflow where id = @Cashflow and DueDate < @Date and InterestEvent = 1
  30. select @ValueDate = ValueDate from IR_Deal where BookingID = @BookingID
  31. select top 1 @PrincipalStart = Principal from v_Cashflow where Id = @Cashflow and PrincipalEvent = 1 order by DueDate asc
  32.  
  33.  
  34. if @DueDate is null
  35. select @DueDate = @ValueDate
  36. else
  37. set @PrincipalStart = 0
  38.  
  39.  
  40.  
  41. select @Value = SUM(isnull(i.AmortisedCost - i.prevAmortisedCost, 0)) + isnull(sum(abs(cf.Interest)), 0) + isnull(sum(ABS(cf.Principal)), 0) - abs(@PrincipalStart)
  42.  
  43. from v_IR_Info i
  44.  
  45. inner join IR_Deal d on d.Ticket = i.Ticket
  46.  
  47. left outer join v_Cashflow cf on cf.Id = @Cashflow and (cf.SettlementInterestDate = i.Date or cf.SettlementPrincipalDate = i.Date) and cf.DueDate <> @ValueDate
  48.  
  49. where i.Ticket = @Ticket
  50.  
  51. and i.Date <= @Date
  52.  
  53. and i.Date > @DueDate
  54.  
  55. end
  56. select @value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement