Should I set a variable in the same line in which it was declared?
It was not possible until SQL Server 2008. Before this version you should declare the variable, and then set its value.

According MS DOCS:


  THIS TOPIC APPLIES TO:
    SQL Server (starting with 2008)
    Azure SQL Database
    Azure SQL Data Warehouse
    Parallel Data Warehouse