请帮我看一下,存储过程怎么没有实现插入和更新的,没有提示语法错误!SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GOALTER    PROCEDURE kq  
(@tbname char(13)='KQBRUSH200904',@flag  char(1)='N',@skrq  char(10)='2009-04-26')
AS
declare @d  char(2)
declare @m  char(2)
declare @zhuan char(2)
declare @y  char(4)
declare @i  varchar(1000)
declare @j  char(3)
declare @z int
declare @zh1  int
declare @zh2  int
declare @w1  int
declare @w2  int
declare @y1  int
declare @sql varchar(1000)
declare @sksj char(255)
--游标插入数据
declare cus cursor for select no from rs where lzrq is null and left(bmno,4)<1009
open cus
declare @no varchar(10)
fetch next from cus into @no
while (@@fetch_status=0)
begin 
  
  if @flag='N'
   begin set @z=rand()*14+16
         set @zh1=rand()*14         if @zh1<10
            begin 
            set @zhuan='0'+left(Convert(char(2),@zh1),1)
            end         set @zh2=rand()*14+16
         set @w1=rand()*14+30
         set @sksj='07:'+Convert(char(2),@z)+',11:'+@zhuan+',12:'+Convert(char(2),@zh2)+',17:'+Convert(char(2),@w1)
  end
  else
     begin    set @z=rand()*14+16
              set @zh1=rand()*14         if @zh1<10
            begin
             set @zhuan='0'+left(Convert(char(2),@zh1),1)
            end              set @zh2=rand()*14+16
              set @w1=rand()*10+30
              set @w2=rand()*10+50
              set @y1=rand()*14+30
              set @sksj='07:'+Convert(char(2),@z)+',11:'+@zhuan+',12:'+Convert(char(2),@zh2)+',17:'+Convert(char(2),@w1)+',17:'+Convert(char(2),@w2)+',20:'+Convert(char(2),@y1)
     end   set @sql='insert '+@tbname +' select name,'+@no+',bmno,bmmc,'+@skrq+',null from rs where no='+@no
  execute (@sql)
  set @sql='update '+@tbname+' set sksj='''+@sksj+''' where skrq='''+@skrq +'''' 
  execute (@sql) 
   fetch next from cus into @no
   set @z=0
   set @zh1=0
   set @zhuan='00'
   set @zh2=0
   set @w1=0
   set @w2=0
   set @y1=0
   end
close cus
deallocate cus
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

解决方案 »

  1.   


    declare cus cursor for select no from rs where lzrq is null and cast(left(bmno,4) as int) <1009 
      

  2.   

    ALTER    PROCEDURE kq  
    (@tbname char(13)='KQBRUSH200904',@flag  char(1)='N',@skrq  char(10)='2009-04-26') 
    AS 
    declare @d  char(2) 
    declare @m  char(2) 
    declare @zhuan char(2) 
    declare @y  char(4) 
    declare @i  varchar(1000) 
    declare @j  char(3) 
    declare @z int 
    declare @zh1  int 
    declare @zh2  int 
    declare @w1  int 
    declare @w2  int 
    declare @y1  int 
    declare @sql varchar(1000) 
    declare @sksj char(255) 
    --add  ************************************************************
    set nocount on 
    --*******************************************************************--游标插入数据 
    declare cus cursor for select no from rs where lzrq is null and left(bmno,4) <1009 
    open cus 
    declare @no varchar(10) 
    fetch next from cus into @no 
    while (@@fetch_status=0) 
    begin 
      
      if @flag='N' 
      begin set @z=rand()*14+16 
            set @zh1=rand()*14         if @zh1 <10 
                begin 
                set @zhuan='0'+left(Convert(char(2),@zh1),1) 
                end         set @zh2=rand()*14+16 
            set @w1=rand()*14+30 
            set @sksj='07:'+Convert(char(2),@z)+',11:'+@zhuan+',12:'+Convert(char(2),@zh2)+',17:'+Convert(char(2),@w1) 
      end 
      else 
        begin    set @z=rand()*14+16 
                  set @zh1=rand()*14         if @zh1 <10 
                begin 
                set @zhuan='0'+left(Convert(char(2),@zh1),1) 
                end               set @zh2=rand()*14+16 
                  set @w1=rand()*10+30 
                  set @w2=rand()*10+50 
                  set @y1=rand()*14+30 
                  set @sksj='07:'+Convert(char(2),@z)+',11:'+@zhuan+',12:'+Convert(char(2),@zh2)+',17:'+Convert(char(2),@w1)+',17:'+Convert(char(2),@w2)+',20:'+Convert(char(2),@y1) 
        end   set @sql='insert '+@tbname +' select name,'+@no+',bmno,bmmc,'+@skrq+',null from rs where no='+@no 
      execute (@sql) 
      set @sql='update '+@tbname+' set sksj='''+@sksj+''' where skrq='''+@skrq +'''' 
      execute (@sql) 
      fetch next from cus into @no 
      set @z=0 
      set @zh1=0 
      set @zhuan='00' 
      set @zh2=0 
      set @w1=0 
      set @w2=0 
      set @y1=0 
      end 
    close cus 
    deallocate cus 
    GO 
    SET QUOTED_IDENTIFIER OFF 
    GO 
    SET ANSI_NULLS ON 
    GO 
      

  3.   

    在看看。
    你这条语句有返回记录吗?
    select no from rs where lzrq is null and left(bmno,4) <1009 
      

  4.   

    只返回 Stored Procedure: stxt.dbo.kq
    Return Code = 0
    提示信息,还是没有插入记录!