I have a query where, depending on a parameter, I need the result in a field to be 5 decimal places or 2 decimal places, is it possible in SQLSERVER 2008?
Example
DECLARE @VALOR DECIMAL(18,2), @PORCENTOJUROS DECIMAL(18,2), @CODJUROS INT
SET @VALOR = 5000.00
SET @PORCENTOJUROS = 2.0
SET @CODJUROS = 1
SELECT
CASE
WHEN @CODJUROS = 1 THEN CAST((((@VALOR / 30.0) / 100.0) * @PORCENTOJUROS) AS NUMERIC(15,2))
WHEN @CODJUROS = 2 THEN CAST((@PORCENTOJUROS / 30.0) AS NUMERIC(12,5))
ELSE 0.0 END [VALOR_MORA]
In this example, if @CODJUROS is 1 I should return a result with 2 decimal places, and if @CODJUROS is 2 I should return a result with 5 decimal places, but both return me with 5 decimal places.