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,实在看不懂了,请高手指点呀.

解决方案 »

  1.   

    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 ' '
      

  2.   

    我也知道不够27行,可能是我回车的原因吧,所以系统就这样提示是27行了,可能就是这里
    (select 职工号  from salary   group by 职工号
    这里都有空行,唉,我还是看不懂呀,能不能说明白一点或