我原来用ASP实现数据批量更新功能,能不能用一个存储过程来完成呢

wcl2222 2010-05-27 10:49:37
我原来是用asp程序来实现的,现在我希望能用存储过程或定期作业来完成,不知我这种想法能不能实现,请高人指点,

我原来的asp代码功能如下:


win=0
set rs=server.CreateObject("ADODB.RecordSet")
sql="select id, ph, un from songph where defen>0"
rs.Open sql,conn,1,1
do while not rs.eof
win=win+1

if win>rs("ph") then

conn.execute"update pk set ph="&win&", un='↓' where id="&rs("id")
else
conn.execute"update pk set ph="&win&", un='↑' where id="&rs("id")
end if
rs.movenext
loop






...全文
112 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wcl2222 2010-05-27
  • 打赏
  • 举报
回复
太感谢了,正是我想要的,我慢慢研究!
永生天地 2010-05-27
  • 打赏
  • 举报
回复
按照你的asp改写的,你测测

create proc p_test()
as
begin
declare @id int,@ph int,@un varchar(2),@i
set @i=0
declare cur_1 cursor for
select id, ph, un from songph where defen>0
open cur_1
fetch next from cur_1 into @id,@ph,@un
while @@fetch_status=0
begin
set @i=@i+1
if @i>@ph
begin
update pk set ph=@i, un='↓' where id=@id
end
else
begin
update pk set ph=@i, un='↑' where id=@id
end
fetch next from cur_1 into @id,@ph,@un
end
close cur_1
deallocate cur_1
end
wcl2222 2010-05-27
  • 打赏
  • 举报
回复
问题我不知道,存储过程是怎么取得查询的结果后,再循环给新记录赋值呢,能简单说下语法吗,谢谢!
永生天地 2010-05-27
  • 打赏
  • 举报
回复
改成存储过程 ,再用定时作业,一点问题没有

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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