我是sql新手.我在查询中出现hv错误是必须声明标量变量 [英] i m new in sql. i hv error in my query is must declare scalar variable

查看:407
本文介绍了我是sql新手.我在查询中出现hv错误是必须声明标量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql query.msg中有错误Massege,

消息137,第15级,州2,第1行
必须声明标量变量"@emp_name".
消息137,第15级,州2,第3行
必须声明标量变量"@emp_name".
消息137,第15级,州2,第4行
必须声明标量变量"@emp_add".
消息137,第15级,州2,第8行
必须声明标量变量"@emp_name".

请告诉我如何解决这些错误.我的查询是

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

推荐答案

Hii,
我认为您忘记选择此游标的声明部分,这就是为什么会发生错误.
您必须选择所有游标",然后执行,它将成功执行.
Becoz我已经做到了,它运行成功.

祝你好运
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


拉希德,

请检查@ emp_name,emp_add.

我对另一个table尝试了相同的查询.但是我得到了答案

请检查.

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


该代码运行良好.我相信您在执行或注释时忘记了包含这些行.


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)


这篇关于我是sql新手.我在查询中出现hv错误是必须声明标量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆