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?
http://sqlfiddle.com/#!3/d41d8/42156
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.
Scalar variables are used to represent individual fixed-size data objects, such as integers and pointers.
Scalar variables contain only one value at a time, and array variables contain a list of values.
You need to select the [Go] from last dropdown.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With