• I am not sure what you meant there about visibility.

    A CTE only exists for the duration of the query with which is defined. You can't assign a value in a CTE to a variable for the same reason you can't do this:

    I assumed you could write to an outside variable if you can access it (i.e. select as I did).

    Also, you said this doesn't work either. Are you talking about the query I sent last. It does work. If you change the @Start variable, the results are different. But it does access the outside variable.

    On my intent, I think I was pretty clear there. I am just trying to find out if there is a way to write to an outside variable from within a CTE, which may not be possible.

    I was trying to make the first query more efficient by using the outside variable and only building the month string once instead of the 12 times it was being built in the first query.

    Thanks,

    Tom