create procedure test_ins
as
declare @empname varchar(10)
declare SOP_Cursor scroll Cursor
for
select empname from t_hr_employee 
for read only open SOP_Cursor
fetch next from SOP_Cursor into @empname
while @@fetch_status=0 
begin
  insert into t_test(thename) values(@empname)
    fetch next from SOP_Cursor into @empname
end 
close SOP_Cursor
deallocate SOP_Cursor 
GO

解决方案 »

  1.   

    不用游标的方法:
    insert into t_test(thename)
      select empname from t_hr_employee
      

  2.   

    create procedure test_ins
    as
    declare @empname varchar(10)
    declare SOP_Cursor scroll Cursor
    for
    select empname from t_hr_employee 
    for read only open SOP_Cursor
    fetch next from SOP_Cursor into @empname
    while @@fetch_status=0 
    begin
      insert into t_test(thename) values(@empname)
        fetch next from SOP_Cursor into @empname
    end 
    close SOP_Cursor
    deallocate SOP_Cursor 
    GO提示:
    服务器: 消息 170,级别 15,状态 1,过程 test_ins,行 13
    第 13 行: ' ' 附近有语法错误。
    服务器: 消息 156,级别 15,状态 1,过程 test_ins,行 15
    在关键字 'end' 附近有语法错误。
      

  3.   

    请把 第 13 行 insert前的不可见字符删除
      

  4.   

    这样试试。。没有错误了
    create procedure test_ins
    as
    declare @empname varchar(10)
    declare SOP_Cursor scroll Cursor
    for
    select empname from t_hr_employee 
    for read only open SOP_Cursor
    fetch next from SOP_Cursor into @empname
    while @@fetch_status=0 
    begin insert into t_test(thename) values(@empname)
    fetch next from SOP_Cursor into @empname
    end 
    close SOP_Cursor
    deallocate SOP_Cursor
    GO
      

  5.   

    呵呵,解决了,谢谢 pbsql,LoveSQL。
    晕倒,确实是“不可见字符”问题!搞了偶老久。
      

  6.   

    噢,...呵呵,TKS!敢问会是些什么字符?什么时候“入侵”进去滴?:)