well there r wasy to achieve that result although i dont know y u gonna do it
anyway, first thing comes to my mind is Cursor & function base
I myself dont recommend cursor for its performance, & also solve it simply
lets go with function
(I used ur field names)
first create a function
Code:
CREATE FUNCTION [dbo].[GetTotalSale] (@no int, @Sum int) RETURNS int AS BEGIN return (SELECT @Sum+SUM(sale) from aaaa WHERE no <= @no)
END
then:
Code:
DECLARE @D bigint
SET @D = 0
SELECT *
FROM (
select * ,dbo.GetTotalSale(no, @D) Sm
from table) Tb
where Sm < 26000
HTH, let me now about it