Error with Declare usage

91 views Asked by At

I would like to learn how to use declare.

My query is like:

declare @iter int
set @iter = 1

error:

Msg 137, Level 15, State 1, Line 1 Must declare the scalar variable "@iter".

Please help!

3

There are 3 answers

0
Chuck On

That can be done in one or two lines:

declare @iter int = 1
go 
-- or
declare @iter int 
set @iter = 1
1
Julio Elgueta On

You just need to put thw two instructions in different lines

declare @iter int
set @iter = 1
0
user2565838 On

I execute these two line separately that's why it won't work cause before I execute set @iter = 1, SQL have cleared the declare command.