Damien
3/27/2007 12:43:00 PM
On Mar 27, 1:23 pm, "Karch" <nos...@absotutely.com> wrote:
> Given the set of data below and an input of 150 (the sum total required),
> the query should return '12/23/2007 12:00:00 AM' (because 75 + 25 +25 +25 =
> 150)
>
> 1 12/22/2007 12:00:00 AM 50
> 2 12/23/2007 12:00:00 AM 25
> 3 3/25/2007 12:00:00 AM 25
> 4 3/26/2007 12:00:00 AM 25
> 5 3/27/2007 12:00:00 AM 75
>
> "Anith Sen" <a...@bizdatasolutions.com> wrote in message
>
Rewritten to force sample data to fit original table definition, fixed
sample data since presumably the 12/2x/2007 data whould presumably
been from 2006:
insert into Counter (Date,Count,Product)
select '20061222', 50 ,null union all
select '20061223', 25 ,null union all
select '20070325', 25 ,null union all
select '20070326', 25 ,null union all
select '20070327', 75 ,null
declare @p int
set @p = 150
select MAX(Date) from
(
select c1.Date,(select SUM(Count) from Counter c2 where c2.Date >=
c1.Date) as Cnt
from Counter c1
) t
where
Cnt >= @p
Could probably be neater
Damien