SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
below is the query :
DECLARE @InputValue INT = 840;
SELECT
@InputValue AS InputValue,
SUM((CASE
WHEN @InputValue >= PRRangeUpto THEN (LEAD(PRRangeUpto, 1, @InputValue) OVER (ORDER BY PRRangeUpto) - PRRangeUpto) * PRRate
ELSE 0
END)) AS TotalAmount
FROM
PRRateRange
WHERE
@InputValue >= PRRangeUpto;
this query gives an error : Windowed functions cannot be used in the context of another windowed function .How to fix it?
Try something like this:
;
with Q as
(
select *, lead(PRRangeUpto, 1, @InputValue) over (order by PRRangeUpto) as ld
from PRRateRange
)
select @InputValue AS InputValue, sum(case when @InputValue >= PRRangeUpto then ld * PRRate end) as TotalAmount
from Q
where @InputValue >= PRRangeUpto
If it does not work, then show details to reproduce the problem.