The way you have it written (a single DECLARE
with each variable separated by a comma) is a single line of declaration of variables. For this reason, in that line, the variable @PTI_R
does not yet exist.
To solve your error, simply declare the variable @PTI
in a new DECLARE
:
declare @Iva decimal(5,2) = (.16),
...las otras variables acá,
@PTI_R decimal(3,2);
declare @PTI decimal(8,2) = @PTI_R * 100;
Now, here is another problem, and that is that you are assigning the calculation ( @PTI_R * 100
) before giving a value to @PTI_R
, so the result of that will be NULL
. You should do:
declare @Iva decimal(5,2) = (.16),
...las otras variables acá,
@PTI_R decimal(3,2);
SET @PTI_R = 23;
declare @PTI decimal(8,2) = @PTI_R * 100;
Finally, a third problem (based on your comment). decimal(3,2)
means that it is a data type that has 3 digits in total , 2 of which are for the decimal part (after the comma). Therefore, the maximum number you can store in that type of data is 9,99
, so it throws you an error when trying to assign it the value 23
.