Must declare the scalar variable “@variable”

 

If there is a variable in the script we run and we have not declared this variable, we will get this error.

For example, with the help of the following script, let’s create a table named “databaseandlogins” in the “TestDB” database.

Then try to add data to this table as follows.

When we try to add data in this way, we will get an error as follows.

After we declare and set the required variables, you will see that the problem is solved when we run it again.

You can learn more about declaring variable in the artilce “Declare Variables in SQL Server(TSQL)

dbtut
Author: dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *