Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
i have error massege in sql query.msg is
 
Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@emp_name".
Msg 137, Level 15, State 2, Line 3
Must declare the scalar variable "@emp_name".
Msg 137, Level 15, State 2, Line 4
Must declare the scalar variable "@emp_add".
Msg 137, Level 15, State 2, Line 8
Must declare the scalar variable "@emp_name".
 
plzzz tell me how can i solve these error. my query is
---declare cursor
declare @emp_name varchar(40)
declare @emp_add varchar(40)
 
---define cursor

declare cursor_employee cursor for
select emp_name,emp_add from employee
 
---open a cursor
open cursor_employee
 
---fetch the cursor
fetch next from cursor_employee into @emp_name,@emp_add
 
print '*emp_name='+ @emp_name
print 'emp_add='+ @emp_add
while(@@fetch_status=0)
begin
---fetch cursor for next rows
fetch next from cursor_employee into @emp_name,@emp_add
end
Posted 5-Sep-12 21:37pm
Edited 5-Sep-12 22:08pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hii,
I think you forgot to select declaration part of this cursor, thats why error occured.
You must select All cursor and then excecute.it will excecute successfully.
Becoz i had done this it was run successfuly.
 
Good luck
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Rashid,
 
Please check the @emp_name,emp_add .
 
I have try same query for another table.but i got answer
 
Please check.
 
<pre lang="sql">declare @taskid varchar(40)
declare @asssto varchar(40)
 
---define cursor

declare cursor_employee cursor for
select taskid,asssto from tasklist
 
---open a cursor
open cursor_employee
 
---fetch the cursor
fetch next from cursor_employee into @taskid,@asssto
 
print  @taskid
print  @asssto
while(@@fetch_status=0)
begin
---fetch cursor for next rows
fetch next from cursor_employee into @taskid,@asssto
end
close cursor_employee
 
deallocate cursor_employee
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The code is perfectly working. I believe you have forgot to include these lines when executing or commented it.
 

declare @emp_name varchar(40)
declare @emp_add varchar(40)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 190
1 PIEBALDconsult 150
2 BillWoodruff 148
3 DamithSL 140
4 Jochen Arndt 125
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 6 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100