“Must declare the scalar variable” error in Toad for SQL

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.

All .mp3 files on Desktop and My Documents folder

Want to know if your users store mp3 files on Desktop or My Documents folders?

  1. Add .mp3 file type to Software Inventory Client Agent properties
      1. Navigate to Site DatabaseSite ManagementSite NameSite SettingsClient Agents and double click Software Inventory Client Agent
      2. Select Inventory Collection tab
      3. Click the new button and type *.mp3 as a file name.
    1. Set the location: All client hard disks or Variable or path name
    2. Click OK to close all open windows
  2. Wait for Software Inventory to run and collect data
  3. Create a report using the following query: SELECT TOP (100) PERCENT SYS.Netbios_Name0, SF.FileName, SF.FileSize / 1024 AS [Size, KB], SF.FilePath FROM dbo.v_GS_SoftwareFile AS SF INNER JOIN dbo.v_R_System AS SYS ON SYS.ResourceID = SF.ResourceID WHERE (SF.FileName LIKE '%mp3') AND (SF.FilePath LIKE '%My Documents%') OR (SF.FileName LIKE '%mp3') AND (SF.FilePath LIKE '%Desktop%') ORDER BY SYS.Netbios_Name0