Calculation with variable

(3 posts) (2 voices)

Tags:

  1. cayasanchez, Member

    I'm trying to create a calculated column using other columns and a variable, but it isn't working, here is my code:

    SET @rate = 0.21; select 'dbr.calc','Lost Net Comp', '([Total_Calls] * @rate) - [phoneSale]';
    If I change the @rate variable by the value, then it works:

    select 'dbr.calc','Lost Net Comp', '([Total_Calls] * 0.21) - [phoneSale]';

    I want to mantain the variable since this is a big report and uses the @rate value multiple times, I want to have declared only once so it would be easy to change in the future.

    Any ideas how the calculation can work using variables instead of fixed values?

  2. myDBR Team, Key Master

    The dbr.calc is avaluated in the myDBR application side. myDBR cannot access the procedure variable, which is why it is not working as expected.

    You've got two options:

    1) Use

    select 'dbr.calc','Lost Net Comp', concat('([Total_Calls] * ',@rate,') - [phoneSale]');

    This way the value of the user defined variable is being passed to myDBR application.

    2) Include the variable to the query and hide it:

    select 'dbr.calc','Lost Net Comp', '([Total_Calls] * [rate_value]) - [phoneSale]';
    
    select 'dbr.hidecolumn', 'rate_value';
    
    select ..., ,@rate as rate_value
    from ...

    --
    myDBR Team

  3. cayasanchez, Member

    Thanks, I will try those options.


Reply

You must log in to post.