I have a table that looks like the below. I am trying to figure out how to update the "endval" column with a value that is from the "startval" column, reduced by 10% for every multiple of 5 in the "effect" column.
declare @tbl table ( rowid int , effect Int , startval decimal(6,2) , endval decimal(6,2) )
insert @tbl values
( 0 , 10 , 6 , null ) -- expect 4.86 in endval
, ( 1 , 40 , 10 , null ) -- expect 4.30 in endval
, ( 2 , 7 , 1 , null ) -- expect .9 in endval
select * from @tbl
Note that rowid 2 does not have an even multiple of 5 in the "effect" column, so it is only reduced by 10% once.
I am trying to come up with any way to "progressively percentage" in TSQL (2012) and nothing is coming to mind. Help?
Thanks.