CREATE PROCEDURE get_pending()
begin
declare t int;--前台的控制标量,没意义
declare i char(64);--分别是查询z_pending 和 z_pend1 表的条件
declare sp datetime;--开始时间
declare ep datetime;--结束时间
DECLARE n int ;--前台的控制标量,应该是时间差一类的设定
declare b int default 1;--sql端的控制变量
--声明游标cur1 --游标查询内容
declare cur1 cursor for select id,end_pending from z_pending where end_pending is not null;
--在n的范围之内 查询 z_penging 表 条件 end_pending 不为空
select count(*) into n from z_pending where end_pending is not null;
--打开游标
open cur1;
--重复查询游标
fetch cur1 into i,ep;
while (@@fetch_status =0)
begin
while (b<n+1)
begin
if b <n+1 then
--根据条件 i,ep 查询 游标依次读取每一条的数据
--获取 z_pend1 中 id 为 i 的有几个
select count(*) into t from z_pend1 WHERE id=i;
case
--从z_pend1或其的内容数量大于1的话
when t>1 then
--在开始时间sp中得到最大的start_pending,并且 z_pending的id为传入的i,start_pending小于结束时间
select max(start_pending) into sp from z_pend1 where id=i and start_pending <ep; update z_pending set start_pending=sp where id=i and end_pending=ep;
--从z_pend1或其的内容数量等于1的话
when t=1 then select start_pending into sp from z_pend1 where id=i;
update z_pending set start_pending=sp where id=i; --上述when两条件都不成立的话执行这段代码,就是说根据传入的条件 i 所查询的结果行数等于 0 .
else
update z_pending set start_pending=null;
--每次循环后在重新设置条件
end case;
set b=b+1;
end if;
--直到条件不成立停止循环
end;
--关闭游标
fetch cur1 into i,ep;
end
close cur1;
end;
begin
declare t int;--前台的控制标量,没意义
declare i char(64);--分别是查询z_pending 和 z_pend1 表的条件
declare sp datetime;--开始时间
declare ep datetime;--结束时间
DECLARE n int ;--前台的控制标量,应该是时间差一类的设定
declare b int default 1;--sql端的控制变量
--声明游标cur1 --游标查询内容
declare cur1 cursor for select id,end_pending from z_pending where end_pending is not null;
--在n的范围之内 查询 z_penging 表 条件 end_pending 不为空
select count(*) into n from z_pending where end_pending is not null;
--打开游标
open cur1;
--重复查询游标
fetch cur1 into i,ep;
while (@@fetch_status =0)
begin
while (b<n+1)
begin
if b <n+1 then
--根据条件 i,ep 查询 游标依次读取每一条的数据
--获取 z_pend1 中 id 为 i 的有几个
select count(*) into t from z_pend1 WHERE id=i;
case
--从z_pend1或其的内容数量大于1的话
when t>1 then
--在开始时间sp中得到最大的start_pending,并且 z_pending的id为传入的i,start_pending小于结束时间
select max(start_pending) into sp from z_pend1 where id=i and start_pending <ep; update z_pending set start_pending=sp where id=i and end_pending=ep;
--从z_pend1或其的内容数量等于1的话
when t=1 then select start_pending into sp from z_pend1 where id=i;
update z_pending set start_pending=sp where id=i; --上述when两条件都不成立的话执行这段代码,就是说根据传入的条件 i 所查询的结果行数等于 0 .
else
update z_pending set start_pending=null;
--每次循环后在重新设置条件
end case;
set b=b+1;
end if;
--直到条件不成立停止循环
end;
--关闭游标
fetch cur1 into i,ep;
end
close cur1;
end;
CREATE PROCEDURE get_pending
begin
declare @t int;--前台的控制标量,没意义
declare @i char(64);--分别是查询z_pending 和 z_pend1 表的条件
declare @sp datetime;--开始时间
declare @ep datetime;--结束时间
DECLARE @n int ;--前台的控制标量,应该是时间差一类的设定
declare @b int default 1;--sql端的控制变量
--所有的变量加@
--声明游标cur1 --游标查询内容
declare cur1 cursor for select id,end_pending from z_pending where end_pending is not null;
--在n的范围之内 查询 z_penging 表 条件 end_pending 不为空
select @n = count(*) from z_pending where end_pending is not null;
--打开游标
open cur1;
--重复查询游标
fetch cur1 into i,ep;
while (@@fetch_status =0)
begin
while (b<n+1)
begin
if b <n+1 then
--根据条件 i,ep 查询 游标依次读取每一条的数据
--获取 z_pend1 中 id 为 i 的有几个
select count(*) into t from z_pend1 WHERE id=i;
case
--从z_pend1或其的内容数量大于1的话
when t>1 then
--在开始时间sp中得到最大的start_pending,并且 z_pending的id为传入的i,start_pending小于结束时间
select max(start_pending) into sp from z_pend1 where id=i and start_pending <ep; update z_pending set start_pending=sp where id=i and end_pending=ep;
--从z_pend1或其的内容数量等于1的话
when t=1 then select start_pending into sp from z_pend1 where id=i;
update z_pending set start_pending=sp where id=i; --上述when两条件都不成立的话执行这段代码,就是说根据传入的条件 i 所查询的结果行数等于 0 .
else
update z_pending set start_pending=null;
--每次循环后在重新设置条件
end case;
set b=b+1;
end if;
--直到条件不成立停止循环
end;
--关闭游标
fetch cur1 into i,ep;
end
close cur1;
end;
我的目标是 ----> ^_^
begin
declare t int;--前台的控制标量,没意义
declare i char(64);--分别是查询z_pending 和 z_pend1 表的条件
declare sp datetime;--开始时间
declare ep datetime;--结束时间
DECLARE n int ;--前台的控制标量,应该是时间差一类的设定
declare b int default 1;--sql端的控制变量
--声明游标cur1 --游标查询内容
declare cur1 cursor for select id,end_pending from z_pending where end_pending is not null;
--在n的范围之内 查询 z_penging 表 条件 end_pending 不为空
select count(*) into n from z_pending where end_pending is not null;
--打开游标
open cur1;
--重复查询游标
fetch cur1 into i,ep;
while (@@fetch_status =0)
begin
while (b<n+1)
begin
if b <n+1 then
--根据条件 i,ep 查询 游标依次读取每一条的数据
--获取 z_pend1 中 id 为 i 的有几个
select count(*) into t from z_pend1 WHERE id=i;
case
--从z_pend1或其的内容数量大于1的话
when t>1 then
--在开始时间sp中得到最大的start_pending,并且 z_pending的id为传入的i,start_pending小于结束时间
select max(start_pending) into sp from z_pend1 where id=i and start_pending <ep; update z_pending set start_pending=sp where id=i and end_pending=ep;
--从z_pend1或其的内容数量等于1的话
when t=1 then select start_pending into sp from z_pend1 where id=i;
update z_pending set start_pending=sp where id=i; --上述when两条件都不成立的话执行这段代码,就是说根据传入的条件 i 所查询的结果行数等于 0 .
else
update z_pending set start_pending=null;
--每次循环后在重新设置条件
end case;
set b=b+1;
end if;
--直到条件不成立停止循环
end;
--关闭游标
fetch cur1 into i,ep;
end
close cur1;
end;