我有一张桌子 ProductPrice
INSERT INTO ProductPrice
(
ProductId,
EffectiveDt,
InactiveDt,
Price
)
我的日期之间有间隔或重叠
到目前为止我所拥有的表格按最早生效日期排名第一,然后是产品ID
这使用
SELECT
pp.ProductId,
pp.EffectiveDt,
pp.InactiveDt,
ROW_NUMBER() OVER (PARTITION BY pp.ProductId ORDER BY pp.EffectiveDt ASC) AS RankByDate
INTO
#ProductrankByDate
FROM
ProductPrice pp
ORDER BY
pp.ProductId
现在我想做的是更新
是否需要 InactiveDt 并使用下一个等级有效Dt 更新它
所以
01/07/2012 , 10/07/2012
15/07/2012 , 20/07/2012
和
01/07/2012 , 10/07/2012
08/07/2012 , 20/07/2012
会成为
01/07/2012 , 14/07/2012
15/07/2012 , 20/07/2012
和
01/07/2012 , 07/07/2012
08/07/2012 , 20/07/2012
我到目前为止
UPDATE pp
SET
pp.InactiveDt = DATEADD(DAY, -1, pdb.EffectiveDt)
FROM
#ProductrankByDate AS pp
INNER JOIN
#ProductrankByDate AS pdb
ON
pp.ProductId = pdb.ProductId
WHERE
pp.RankByDate = pdb.RankByDate + 1
AND pp.ProductId = pdb.ProductId
但显然这不起作用,所以修改这个或新语句的任何帮助都会有很多帮助谢谢