Posted by MC on 12/07/05 09:16
Is this good enough?
select top 1 Payment_date,
(select sum(Payment) from testsum where Payment_date <= t1.Payment_date)
from testsum t1
where (select sum(Payment) from testsum where Payment_date <=
t1.Payment_date)>3600
order by Payment_date
-----
select top 1 t1.Payment_date, sum(t2.Payment) as suma
from
testsum t1
left join testsum t2 on t1.Payment_date >= t2.Payment_date
group by t1.Payment_date
having sum(t1.Payment)>3600
order by Payment_date
MC
"russzee" <trusst_3@hotmail.com> wrote in message
news:1133923717.618716.252890@g44g2000cwa.googlegroups.com...
>I have a table with the following columns
>
> ---------------------------------------------
> Payment Payment_Date
> --------------------------------------------
> 900 5/15/05
> 900 615/05
> 900 7/15/05
> 900 8/15/05
> 900 9/15/05
> -------------------------------------------
>
> I also have a predetermined value @total = 3600
>
> I need to write a SQL query where it returns the Payment_Date as soon
> as SUM(Payment) > 3600.
>
> So , in this case the returned result would be 9/15/05
>
> I know I can do this via cursors but i was wondering if there is a sql
> query which can accomplish this.
>
>
> TIA
> - Mr. Z
>
Navigation:
[Reply to this message]
|