本人刚学SQL,实在看不懂了,请高手指点呀.

sjyzx 2006-07-26 08:58:15
use factory
go
set nocount on
-- 声明变量
declare @no int,@name char(10)
--声明游标
declare w_cursor cursor
for select 职工号,姓名
from worker
where 职工号 in
(select 职工号

from salary

group by 职工号
having avg(工资)<(select avg(工资) from salary))
--打开游标
open w_cursor
--提取每一行数据
fetch next from w_cursor into @no,@name
--打印表标题
print '职工号 姓名'
print '---------'
while @@fetch_status= 0
begin
--打印一行数据
print cast(@no as char(8))+@name
--提取下一行数据
  
fetch next from w_cursor into @no,@name
end
--关闭游标
close w_cursor
--释放游标
DEALLOCATE w_cursor
go



服务器: 消息 170,级别 15,状态 1,行 27
第 27 行: ' ' 附近有语法错误。

本人刚学SQL,实在看不懂了,请高手指点呀.
...全文
153 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjyzx 2006-07-26
  • 打赏
  • 举报
回复
知道错在哪里就好了
NinGoo 2006-07-26
  • 打赏
  • 举报
回复
首先找到报错的具体部分,看看是不是语法错误了
sjyzx 2006-07-26
  • 打赏
  • 举报
回复
我也知道不够27行,可能是我回车的原因吧,所以系统就这样提示是27行了,

可能就是这里
(select 职工号

from salary

group by 职工号
这里都有空行,唉,我还是看不懂呀,能不能说明白一点或
LouisXIV 2006-07-26
  • 打赏
  • 举报
回复
use factory
go
set nocount on
-- 声明变量
declare @no int,@name char(10)
--声明游标
declare w_cursor cursor
for select 职工号,姓名
from worker
where 职工号 in
(select 职工号

from salary

group by 职工号
having avg(工资)<(select avg(工资) from salary))
--打开游标
open w_cursor
--提取每一行数据
fetch next from w_cursor into @no,@name
--打印表标题
print '职工号 姓名'
print '---------'
while @@fetch_status= 0
begin
--打印一行数据
print cast(@no as char(8))+@name
--提取下一行数据

fetch next from w_cursor into @no,@name
end
--关闭游标
close w_cursor
--释放游标
DEALLOCATE w_cursor
go

--Check the difference betwwen ' ' and ' '
NinGoo 2006-07-26
  • 打赏
  • 举报
回复
第 27 行是哪一行?

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧