I had an issue where I couldn’t use a column that was being evaluated with a modulus statement, the problem was the order of the execution.
Statement in question:
1 | declare @lowerBound int = 0; |
This moans with invalid column name lastThreeDigits
the reason for this is the order of execution in the SQL statement being:
1 | This isn't always the order but it's the normal one: |
So the WHERE is before the SELECT (where I had the alias the column lastThreeDigits
) so it doesn’t exist at the point the WHERE is executed.
The solution was to give SQL a little more work to do:
1 | declare @lowerBound int = 0; |