Question

Photo of Cody Tindall

0

Variables and Dynamic Data Blocks

If I define a custom variable in an sql query and store a value in it, how would I display that variable using the formatted output section of a dynamic data block. How would I call the variable?

Query example:

DECLARE @Deposit INT
    
SET @Deposit = (SELECT SUM(Amount) FROM [FinancialTransactionDetail])

SELECT @Deposit

  • Photo of David Leigh

    1

    Hi Cody,

    I think you might be able to do this with a slight change to your query - you just need to return the custom variable with a column name, like this:

    DECLARE @Deposit INT
    SET @Deposit = (SELECT SUM(Amount) FROM [FinancialTransactionDetail])
    SELECT @Deposit AS TotalDeposit

    Then I think it should be possible to use Michael's solution like this:

    {% for row in rows %}
      {% row.TotalDeposit %}
    {% endfor %}

    This is just a guess (I haven't tested it) - let me know if it comes close to fixing your problem.

  • Photo of Michael Garrison

    0

    First, I don't know the answer to your question. But is there a reason you wouldn't just use the return from the SELECT itself? Such as the Query being:

    SELECT SUM([Amount]) AS Amount FROM [FinancialTransactionDetail]

    And printing it using the formatted output section:

    {% for row in rows %}
      {% row.Amount %}
    {% endfor %}

     

    • Cody Tindall

      Thanks for the response, while this would work in the example I posted, I really need to be able to call custom variables in the formatted output section.