Based on experimentation, here's what I found:
Can you do this:
@saldo_a_depreciar FLOAT = @costo_adquisicion / @vida_util
. Answer: no, SQL Server (2012 in my case) saysIncorrect syntax near '/'
. Wrapping it in parentheses (the last resort of the desperate :-) didn't help either.Can you do this:
@periodo_saldo_cero CHAR(6) = NULL
. Answer: yes, and if@periodo_saldo_cero
isn't passed it defaults to NULL.
As for your @saldo_a_depreciar
column: is it always defined as @costo_adquisicion / @vida_util
? If so you should calculate it as needed rather than storing it.
If @saldo_a_depreciar
really is a value that should be stored rather than calculated, you just need to push the calculation into the procedure code rather than the parameter list:
CREATE PROCEDURE [SISACT].[new_activo_fijo]
@activo VARCHAR(8) ,
@descripcion VARCHAR(60) ,
@utiliza_serial BIT,
@serial VARCHAR(20) = NULL,
@fecha_adquisicion DATE,
@referencia VARCHAR(10),
@costo_adquisicion FLOAT,
@vida_util INT,
@saldo_a_depreciar FLOAT = NULL
@ultimo_periodo CHAR(6),
@periodo_saldo_cero CHAR(6) = NULL,
@fecha_incorporacion DATE,
@fecha_desincorporacion DATE,
@proveedor VARCHAR(8),
@situacion INT
AS
IF @saldo_a_depreciar IS NULL SET @saldo_a_depreciar = @costo_adquisicion / @vida_util
INSERT INTO ... (and the rest of your procedure)
This will calculate @saldo_a_depreciar in two cases: (1) if you don't pass the parameter and (2) if you pass the parameter as null.