Advertisement
Borrisholt

BaseCalculation

May 27th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.93 KB | None | 0 0
  1. use master
  2. go
  3. if DB_ID('TestData') IS NOT NULL
  4.   drop database TestData
  5. go
  6. create database TestData
  7. go
  8. use TestData
  9. go
  10.  
  11. Create table Base
  12. (
  13.   SBase int
  14. )
  15.  
  16. insert into Base (SBase)  values
  17.   (18000), (18100),(18200),(18300),(18400),(18500)
  18.  
  19. go
  20. create or alter function BaseCalculation(@SBase float, @valueA float , @ValueB float )
  21. returns @ResultTable table
  22. (
  23.   SBase int,
  24.   Sout float,
  25.   Spost float,
  26.   Cotis float,
  27.   Salarie float
  28. )
  29. as
  30. BEGIN  
  31.   declare @fValueA  float = @valueA /100
  32.   declare @fValueB  float = @valueB /100
  33.   declare @Sout     float = @SBase * @fValueA
  34.   declare @SPost    float = @SBase + @Sout
  35.   declare @Cotis    float = @Spost * @FValueb
  36.   declare @Salarie  float = @Spost - @Cotis
  37.   insert into @ResultTable
  38.     values (@SBase, @Sout, @SPost, @Cotis, @Salarie)
  39.   return
  40. END
  41. go
  42.  
  43.  
  44. select
  45.     b.SBase, Calculations.* from Base B
  46. cross apply
  47.     dbo.BaseCalculation(b.SBase, 5,9) as Calculations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement