It's because you are using go between the statement that declares the variable and the statement that uses it.
The go command is not an SQL command, it's a separator between sessions in Management Studio. Just remove all the go commands in your query, and you can use the variable all the way.