Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.86 KB | None | 0 0
  1. --declare @recid varchar(15) , @erechbuza datetime, @schumRibitPigurim decimal (18,2) , @HovRibitPigurimToday decimal (18,2)
  2.  
  3. --set @recid= (select min(recid) from contact1 )
  4.  
  5. --while isnull(@recid,'')<> ''
  6. --begin
  7.  
  8. --set  @erechbuza= (select erechbuza from #PigurTashlum where recid=@recid)
  9. --set  @schumRibitPigurim = (select schumRibitPigurim from #PigurTashlum where recid=@recid)
  10.  
  11.  
  12. --update gp_gemel..HovotMasikim
  13. --set HovRibitPigurimToday= select [dbo].[sp_u_Return_HovRibitPigurimToday] (@erechbuza,@schumribitpigurim)
  14. --where recid= @recid
  15.  
  16. --set @recid= (select min(recid) from #pigurtashlum p where p.recid > @recid)
  17. --end
  18.  
  19. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  20.  
  21. create FUNCTION [dbo].[sp_u_Return_HovRibitPigurimToday]
  22. (@ErechBuza datetime ,
  23.  @schumRibitPigurim decimal (18,2))
  24.  returns decimal(18,2)
  25. as
  26.  
  27. BEGIN
  28. declare @FinishDate datetime = (select dateadd(day,-1,max(Ribit_Date)) from RibitHashkal ) --תמיד יחזיר יום לפני אחרון בהנחה ומעודכן עד היום
  29.  
  30. while @ErechBuza <= @FinishDate
  31. begin
  32.  
  33.    declare @HovRibitPigurimToday decimal(18,2)
  34.    declare @Daily_Ribit decimal(18,2) = ( select Ribit from RibitHashkal rh where rh.Ribit_Date = @ErechBuza)
  35.  
  36.  
  37.    set @HovRibitPigurimToday= @schumRibitPigurim * ( 1 + @Daily_Ribit/100/365) ---עדכון חוב התחלתי
  38.    set @ErechBuza = dateadd(day,1,@ErechBuza)
  39.    set @schumRibitPigurim=@HovRibitPigurimToday
  40. end
  41.  
  42.  
  43. return @HovRibitPigurimToday
  44. END
  45.  
  46. --create  table RibitHashkal  (Ribit_Date datetime ,Ribit decimal(18,2) )  
  47. --insert into RibitHashkal values ('2018-06-25 00:00:00.000','50.00')
  48. --select* from RibitHashkal
  49.  
  50. --select [dbo].[sp_u_Return_HovRibitPigurimToday] ('2018-06-23 00:00:00.000','600.00')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement