我正在尝试计算运行成本,我需要帮助一个过程,当它的值为0时,将列行值复制到下一行。这里我想将第2行的0.99复制到第3行和放大器; 4他们是0.在此之后我想向前移动0.66然后向前移动0.36。我希望这格式很好,这是我在这里的第一篇文章。谢谢你的帮助。
lngPipeRunID lngPipeGroupID lngInOutID RunLoadFootage RunFootage RunLoadCost RunCostFoot
1 1 1 4549.0000 4549.0000 4503.51 0.99
2 1 1 -1523.2200 3025.7800 -1507.99 0.99
3 1 2 -2491.7300 534.0500 0.00 0.00
4 1 2 -96.0000 438.0500 0.00 0.00
5 1 1 8471.6800 8909.7300 11930.92 1.4083
6 2 1 261.0000 261.0000 172.26 0.66
7 2 1 221.4200 482.4200 0.00 0.00
8 2 1 1191.5100 1673.9300 428.94 0.36
9 2 2 -1673.9300 0.0000 0.00 0.00
10 2 1 42.9800 42.9800 0.00 0.00
11 2 2 -42.9800 0.0000 0.00 0.00
答案 0 :(得分:0)
尝试以下查询
WHERE Dog_Id LIKE '%1' AND Cat_Id LIKE '%1'
答案 1 :(得分:0)
这对我有用,有没有办法用val更新RunCostFoot?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE spPipeRun_09_upd_RunCostFoot
AS
SET NOCOUNT ON;
BEGIN
DECLARE
@ID INT = NULL,
@RCF MONEY = NULL
SELECT
@ID = lngPipeRunID,
@RCF = RunCostFoot
FROM
tbl_Pipe_Run
WHERE
lngPipeRunID = @ID;
WITH cte (RNO, VAL) AS
(
SELECT lngPipeRunID AS RNO,
RunCostFoot AS VAL
FROM tbl_Pipe_Run
WHERE lngPipeRunID=1
UNION all
SELECT RNO+1 as RNO
, CASE WHEN RunCostFoot =0 then VAL
else RunCostFoot end as VAL
FROM tbl_Pipe_Run t
join cte ON t.lngPipeRunID=cte.RNO+1
)
SELECT *
from cte
option (maxrecursion 0)
END;