Started learning how to work with variables in T-SQL. Doing first basic exercise to declare today’s date and then print it, failed mizerably.
I was using Toad for SQL because this is my day to day tool. Tried several other examples, searched online for this error… looks like “it works”, but it doesn’t for me?!
Opened Microsoft SQL Management Studio, pasted same example, hit F5. Boom, worked! Ok, then it’s something related to Toad for SQL.
Searched again with Toad word included. Of course, found the issue description quickly on Toad’s forum: https://forums.toadworld.com/t/data-point-error-must-declare-the-scalar-variable/27407/8
This is not a bug and that is why things are not changing. This is original behavior from Toad for Oracle.
There are different execution needs depending on what you are doing.
When you have a script you might want to only execute the SQL you are working on. For this you use F9 and we figure out what the current statement is based on your cursor and only execute that.
Or when you have a script you might want to execute all in the script from top down. For this you use F5.
There is a third option which is to execute from the current statement to the end. For this there is a menu action but no hot key.
In the case of a SQL that contains a script variable you can’t execute the current statement as the variable must be declared in block of code that is being sent to the server. So in this case F5 is the only option.