日期:2014-05-17  浏览次数:21046 次

要实现每天某个字段都自动减去1,请高手帮忙
比如我输入数据库某字段为100,就是要每天都自动减   1。也就是第2天变成99,第3天变成98了……  
然后直到100天后,减到   0   ,就不减了,怎么做呢?
我是菜鸟,请给出实际代码,谢谢各位高手


------解决方案--------------------
<script>
function SystemMessage(){
SystemMessageOutTime = SystemMessageOutTime + 1;
if(resizeMessage || SystemMessageOutTime> 3){
resizeMessage = false;
SystemMessageOutTime = 0 ;
//window.open ( "SysMessage.asp ");
window.SystemMessageWindow.location.href = "SysMessage.asp ";
}
setTimeout( "SystemMessage() ",36240000);
}
function DataReload() {
SystemMessageOutTime = 4;
SystemMessage();
if(top.Main.DataReload != null){
top.Main.DataReload();
}else{
if(top.Main.Note != null){
if(top.Main.Note.DataReload != null){
top.Main.Note.DataReload();
}
}
}
}

</script>
<%
'连数据库
'取字段值
if "字段值 " > 0 then
'操作 字段值 - 1
else
'不操作
end if
%>
------解决方案--------------------

sub setcount(n)
conn.execute "update table set countdate=getdate() "
end sub


function getcount()
dim rs
set rs=conn.execute( "select DATEDIFF(day, countdate, getdate()) from table "
getcount=rs(0)
end function

------解决方案--------------------
在数据库写一个触发计划任务,写一个过程,每天触发一次这个过程,在过程中判断是否减一
------解决方案--------------------
用法:
1、设置计数器: setcount
2、判断计数器到多少了:

count=n-getcount
if count <0 then count=0
------解决方案--------------------
初学者我觉得不会有这种需求,没有特殊情况,数据库不应该天天去改,你要的效果在显示的时候判断就可以,数据库存一个加入的日期,判断当前日期和数据库的日期相差的天数就是你要的数据了