疑难问题,占用邹老大一点点时间,求解
A表价格信息表(价格信息)
ID,ItemID,CustomID,Price,Price2
B表调价表(调价明细)
ID,ItemID,CustomID,Price,BeginDate,EndDate
每天执行一次对调价明细进行检查,更新价格信息
1,如果Date在BeginDate与EndDate间则取EndDate最大的那条记录作用A表,如果A表没相对应ItemID,CustomID,就插新记录,如果存在则Update Price
2,如果Date-EndDate=1(时间为昨天结束的调价单),则要取Date在BeginDate与EndDate间则取EndDate最大的那条记录作用A表Update,根据ItemID,CustomID,如果找不到记录则把A表中Price2写入Price
问题点数:0、回复次数:6Top
1 楼yingqing(曾明)回复于 2004-12-04 15:57:37 得分 0
不大明白你的意思,Date是不是當前日期或者某個固定值,是的話用遊標對表B遍歷可以實現Top
2 楼zjcxc(邹建)回复于 2004-12-04 16:23:50 得分 0
和上次的那个差不多吧Top
3 楼zjcxc(邹建)回复于 2004-12-04 16:27:54 得分 0
--没看出第二个条件与第一个条件有什么处理上的不同,不都是取"EndDate最大的那条记录"么?
--"Date-EndDate=1",这个条件也是包含在"Date在BeginDate与EndDate间"中吧
--更新处理的存储过程(定时执行用作业,上个帖已经回复过了)
create proc p_process
as
declare @dt datetime
set @dt=convert(char(10),getdate(),120) --去掉时间影响,只比较日期部分
--得到最新的调价信息
select b.ItemID,b.CustomID,Price=max(b.Price)
into #t
from B表 b,(
select ItemID,CustomID,EndDate=max(EndDate)
from B表
where BeginDate<=@dt and EndDate>=@dt
group by ItemID,CustomID
)b1 where b.BeginDate<=@dt and b.EndDate>=@dt
and b.ItemID=b1.ItemID and b.CustomID=b1.CustomID
and b.EndDate=b1.EndDate
group by b.ItemID,b.CustomID
--更新已经存在的价格
update a set Price=b.Price
from A表 a,#t b
where a.ItemID=b.ItemID and a.CustomID=b.CustomID
--插入A表中没有的
insert A(ItemID,CustomID,Price)
select ItemID,CustomID,Price
from #t b
where not exists(
select * from A表
where ItemID=b.ItemID and CustomID=b.CustomID)
go
Top
4 楼wofan(我烦)回复于 2004-12-04 16:48:34 得分 0
第二个条件有点不同
B表数据已经写入A表中
判断结束日期如果已经过了今天(此存储是零点以后执行)的相对应A表中的Price用B表中新的价格策略(此方法和1相同,执行Update这一步。因为A表中已有相对应的Item,Custom所以insert这个方法就用不着了)写入A表,如在B表中找不到相应的价格策略的话,则把A表中历史Price2的价格写回Price
Top
5 楼wofan(我烦)回复于 2004-12-09 09:58:07 得分 0
顶上去Top
6 楼vinsonshen(为了明天)回复于 2004-12-09 10:11:20 得分 0
帮你顶下先咯~~Top




