ALTER procedure upyz as begin declare @zz numeric(9,2) declare @yz numeric(9,2) declare @tz int declare @yxrq datetime declare @ht varchar(20) declare @wylevel int declare @wywzid int declare @yzfy numeric(9,2) declare getht cursor for select ht_num from fytable order by ht_num open getht fetch next from getht into @ht while @@fetch_status=0 begin declare getwy cursor for select wy_level ,wy_wzid from ht_wyy where ht_num=@ht order by wy_level open getwy fetch next from getwy into @wylevel,@wywzid while @@fetch_status=0 begin select @zz=zz_percent ,@yz=sjyzj ,@tz=tznx,@yxrq=rzsj from ht_wyy where ht_num=@ht and wy_level=@wylevel and @wywzid=@wywzid --if dateadd(month,@tz,@yxrq)=convert(datetime,floor(convert(float,getdate()))) if convert(varchar(10),dateadd(month,@tz,@yxrq),112)=convert(varchar(10),getdate(),112) begin update ht_wyy set ysyzj=sjyzj, sjyzj=(@zz+1)*@yz where ht_num=@ht and wy_level=@wylevel and @wywzid=@wywzid select @yzfy=yzy from fytable where ht_num=@ht select @yzfy=@yzfy-@yz+(@zz+1)*@yz update fytable set yzy=@yzfy where ht_num=@ht end fetch next from getwy into @wylevel,@wywzid end close getwy deallocate getwy fetch next from getht into @ht end close getht deallocate getht end我在表里面只放一条记录,把系统时间调到需要的时间,但是UPDATE没有执行,我调试 了一下,在IF 那里调到了CLOSE 那里。说明不相等啊
if convert(varchar(8),dateadd(month,@tz,@yxrq),112)=convert(varchar(10),getdate(),112)
附:
select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108) ---06:05:05
101 美国 mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英国/法国 dd/mm/yy
4 104 德国 dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*) 默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美国 mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*) 欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 或 120 (*) ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff]
- 21 或 121 (*) ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff]
- 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格)
- 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM
- 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM
as
begin
declare @zz numeric(9,2)
declare @yz numeric(9,2)
declare @tz int
declare @yxrq datetime
declare @ht varchar(20)
declare @wylevel int
declare @wywzid int
declare @yzfy numeric(9,2)
declare getht cursor
for select ht_num from fytable order by ht_num
open getht
fetch next from getht into @ht
while @@fetch_status=0
begin
declare getwy cursor
for select wy_level ,wy_wzid from ht_wyy where ht_num=@ht order by wy_level
open getwy
fetch next from getwy into @wylevel,@wywzid
while @@fetch_status=0
begin
select @zz=zz_percent ,@yz=sjyzj ,@tz=tznx,@yxrq=rzsj from ht_wyy where ht_num=@ht and wy_level=@wylevel and @wywzid=@wywzid
--if dateadd(month,@tz,@yxrq)=convert(datetime,floor(convert(float,getdate())))
if convert(varchar(10),dateadd(month,@tz,@yxrq),112)=convert(varchar(10),getdate(),112)
begin
update ht_wyy set ysyzj=sjyzj, sjyzj=(@zz+1)*@yz where ht_num=@ht and wy_level=@wylevel and @wywzid=@wywzid
select @yzfy=yzy from fytable where ht_num=@ht
select @yzfy=@yzfy-@yz+(@zz+1)*@yz
update fytable set yzy=@yzfy where ht_num=@ht
end
fetch next from getwy into @wylevel,@wywzid
end
close getwy
deallocate getwy
fetch next from getht into @ht
end
close getht
deallocate getht
end我在表里面只放一条记录,把系统时间调到需要的时间,但是UPDATE没有执行,我调试
了一下,在IF 那里调到了CLOSE 那里。说明不相等啊