Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2009-03-30 : 06:57:29
|
| I have this functionALTER FUNCTION [dbo].[eMatrixAddVehicle_f_CalculateInitPrice] ( @RoundToNearest bit, @InitPrice money, @AddPrice money, @PriceType varchar(20))RETURNS moneyASBEGIN SET @InitPrice = @InitPrice + CASE @PriceType WHEN 'POUNDS' THEN @AddPrice ELSE @InitPrice * @AddPrice / 100 END IF @RoundToNearest = 1 SET @InitPrice = CEILING(@InitPrice) + 0.99 RETURN @InitPrice ENDI need to modify it so thatIf @InitPrice > 0.00 Then/* Do the functionElse/* Do nothing / return unmodified @InitPriceEnd IfHow can I do this?Thanks |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-03-30 : 07:11:51
|
| Just use a IF statement.ALTER FUNCTION [dbo].[eMatrixAddVehicle_f_CalculateInitPrice] (@RoundToNearest bit,@InitPrice money,@AddPrice money,@PriceType varchar(20))RETURNS moneyASBEGINIF @InitPrice > 0BEGIN SET @InitPrice = @InitPrice + CASE @PriceType WHEN 'POUNDS' THEN @AddPrice ELSE @InitPrice * @AddPrice / 100 END IF @RoundToNearest = 1 SET @InitPrice = CEILING(@InitPrice) + 0.99ENDRETURN @InitPrice END |
 |
|
|
Mondeo
Constraint Violating Yak Guru
287 Posts |
Posted - 2009-03-30 : 08:24:58
|
| OK great thanks.Struggling with this oneRETURN CASE @RoundToNearest WHEN 1 THEN CEILING(@result) - 0.01 ELSE @result ENDIf @result = 0.00 then I want to return @result, else I want to return the CEILING method. I cant get it to work nesting an IF statement within the CASE. |
 |
|
|
|
|
|