• ronmoses (4/30/2013)


    Bob Cullen-434885 (4/30/2013)


    So here's a question. If variables are initialized at parsing time - I take this to mean that the DECLARE is interpreted prior to the INSERT - why can't you declare a variable later in the code than it's used? You can't swap out the IF and ELSE branches in this example. Not that you'd want to do it, it's just an academic question.

    ron

    Because the code will fail during parse time - it references an object which does not exist.

    Parser will just stop reporting an error and never reach the line in code where the variable is declared.

    Therefore it will never get to compilation stage when DECLARE would be executed and @Variable could be materialised in memory.

    _____________
    Code for TallyGenerator