alter Function fn_PercentualDesconto (@Fullvalue float, @EndValue float)
Returns Float
Begin
declare @v01 float;
declare @v02 float;
declare @v03 float;
Set @v01=@Fullvalue
Set @v02=@EndValue
Set @v03=(@v01-@v02)
Return 100- round((@v03 / @v01 ) * 100 , 2)
End
alter Function fn_PercentualDesconto (@Fullvalue float, @EndValue float)
Returns Float
Begin
Return round( (@EndValue / @Fullvalue) * 100, 2)
End
If the possibility to have @Fullvalue = 0.0 exists then add one condition:Return CASE WHEN @Fullvalue = 0.0 THEN 0.00 ELSE round( (@EndValue / @Fullvalue) * 100, 2) END
Or generate some error.ASKER
Set @v01=@Fullvalue
Set @v02=@EndValue
Set @v03=(@v01-@v02)
Return 100- round((@v03 / @v01 ) * 100 , 2)
Set @v01 = 60
Set @v02 = 54
Set @v03 = (60-54) <-- @v03=6
Return 100 - round (6 / 60 * 100, 2) <-- return 100 - 10, or 90
Sounds like your code is doing exactly what you told it to.
ASKER
ASKER
Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the Always On technologies and support for unstructured data types.
TRUSTED BY
with
Open in new window
100 is an integer