How to interpret this code?

  • I'm a newbie and trying to understand what does this code do. The only information I have about this code is that it used to calculate values from year 2015 to 2001. I don't understand how this code works. Is there anyone can help me with interpreting the code?

    SET @MYYEAR = @FIRST_YEAR

    SET @QUERY = "UPDATE BACKWARD_PASS SET "

    WHILE (@MYYEAR <= @LAST_YEAR - 1)

    BEGIN

    IF (@MYYEAR <> @LAST_YEAR - 1)

    BEGIN

    SET @QUERY = @QUERY +

    "Calculate_Backward." + '[' + cast(right(@MYYEAR,2) as VARCHAR(10)) + ']' +

    " = cast(nullif(" + '[' + cast(@MYYEAR as VARCHAR(10)) + ']' + ",0) as float(1))/cast(nullif(" +

    '[' + cast(@MYYEAR+1 as VARCHAR(10)) + ']' + ",0) as float(1)),

    "

  • Well this code is making a Dynamic Query based upon the parameter(s) value and if you want to check whats is making in the end. In the end of the code place the following :

    SELECT @QUERY

    this will give you the complete query copy the text and paste it in a t-sql and you will understand what its actually doing.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply