Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLFiddle: must declare the scalar variable error

Tags:

sql

sqlfiddle

I'm trying to execute next SQL statement (SQL Server 2008 Profile)

DECLARE @fun int;
SET @fun = 40;

select cast(@fun as varchar(10)) + 'hello'

and SQLFiddle gives me the error: Must declare the scalar variable @fun

Where I'm wrong?

enter image description here

http://sqlfiddle.com/#!3/d41d8/42156

like image 276
Andrey Morozov Avatar asked Jan 07 '15 18:01

Andrey Morozov


People also ask

What is the meaning of must DECLARE the scalar variable?

A scalar variable declaration specifies the name and data type of the variable and allocates storage for it. The declaration can also assign an initial value and impose the NOT NULL constraint. You reference a scalar variable by its name.

What is scalar variable in C#?

Scalar variables are used to represent individual fixed-size data objects, such as integers and pointers.

How many values can be stored in a scalar variable SQL?

Scalar variables contain only one value at a time, and array variables contain a list of values.


2 Answers

You need to select the [Go] from last dropdown.

like image 156
Ashish Bisht Avatar answered Nov 08 '22 22:11

Ashish Bisht


I think the semicolons are introducing the problem here.

As described here: http://www.sql-server-helper.com/error-messages/msg-137.aspx and here: SQL Server - Variable declared but still says "Must declare the scalar variable", the problem arises when the statements are executed individually instead of as a “unit”, and the semicolons seem to trigger that.

When I remove the semicolons from your statement, it works: http://sqlfiddle.com/#!3/d41d8/42159

like image 21
CBroe Avatar answered Nov 08 '22 22:11

CBroe