你用:insert 另外一个表 (列名1,列名2) select 列名1,列名2 from 一个表来代替游标

解决方案 »

  1.   

    为什么认为是游标的原因呢,一般来说即使你写的select语句,系统也会使用隐性游标,而用declare语句定义的游标,只不过是显性游标而已,我认为没有什么差别。目标表上是不是建有索引。
      

  2.   

    我的函数代码如下:好像大力的办法不行吧declare @mobile_id varchar(100)
    declare @msg_cont varchar(200)
    declare @tocode  varchar(100)
    declare @info_data_uptime  varchar(100)
    declare CustCursor scroll Cursor for
    select tocode,mobile_id,msg_cont,info_data_uptime 
    from it_198 where  send_time=convert(char(5),getdate(),8)
    open CustCursor
     -- print convert(char(5),getdate(),8 )
      fetch next from CustCursor 
      into @tocode,@mobile_id,@msg_cont,@info_data_uptime  
      
      while (@@fetch_status=0)
      begin
         insert into web_send (phone,msgcontent)   values (@mobile_id,@msg_cont)
          update project_send set al_send_time=@info_data_uptime  where tocode=@tocode     
         fetch next from CustCursor 
         into @tocode,@mobile_id,@msg_cont,@info_data_uptime 
      end
      

  3.   

    大力的办法可以的。你好好尝试一下。
    TO enhydraboy(乱舞的浮尘)  
      虽然系统使用了隐性的游标,可是它不占用很多资源,而且它的使用机制和咱们定义的也不同。你可以试一下。使用游标和不使用游标的速度差别。数据越多越慢。当然如果数据量只有4000行左右的时候,游标快。当数据达到10000行的时候,你就知道游标的可怕了。
      

  4.   

    to liuyunfeidu(飞龙) :  可是我还有update指令啊!
      

  5.   

    试试:
    insert into web_send (phone,msgcontent)   
    select mobile_id,msg_cont 
    from it_198 where  send_time=convert(char(5),getdate(),8)update project_send set al_send_time=
    select info_data_uptime @info_data_uptime  
    from it_198 
    where send_time=convert(char(5),getdate(),8)
         and tocode=project_send.tocode
      

  6.   

    to ian2000(粗人) 多谢你的帮助,insert是可以了,但是我发现update还是不可以,执行的结果是将project_send中的满足条件的记录的al_send_time字段都改成了it_198中满足条件的第一个字段的值。这显然是不行的,看看还有什么办法没有。
      

  7.   

    while (@@fetch_status=0)
      begin
         insert into web_send (phone,msgcontent)   values (@mobile_id,@msg_cont)
          update project_send set al_send_time=@info_data_uptime  where tocode=@tocode ---把这一句改一下,试试
    /////update project_send set al_send_time=@info_data_uptime  where CURRENT OF CustCursor
    //////主要我考虑是不是由于你的语句中更新时又进行了一次查找,浪费了时间
         fetch next from CustCursor 
         into @tocode,@mobile_id,@msg_cont,@info_data_uptime 
      end
      

  8.   

    to hnwlk() 那你的要求是什么?
      

  9.   

    to :ian2000(粗人) 比如数据如下it_198有两条记录tocode   info_data_uptime 
    12345     2003-5-1
    45678     2004-1-1project_send有两条记录tocode     al_send_time
    12345       2002-1-1
    45678       2002-1-1我想要的sql是执行update后,peoject_send内容更新为
    tocode     al_send_time
    12345       2003-5-1
    45678       2004-1-1(或者将al_send_time统一为目前的时间也可以)
    按照你写的sql,执行以后,peoject_send内容更新为
    tocode     al_send_time
    12345       2003-5-1
    45678       2003-5-1
      

  10.   

    你可以这么写啊。insert into it_198(列) select 列 from table where 条件
       update  peoject_send set al_send_time=it_198.info_data_uptime  from it_198,peoject_sent where peoject_send.tocode=it_198.tocode
    这么写的前提是你的那个tocode字段是唯一值。