I have been looking half a day and cannot really find a proper solution... Well not quite true, I have a solution that works... but I dont like it.
In Oracle you can use the sum() Partition by to create a running sum... or running count()... In SQL Server this doesnt seem possible....
What I have now:
Note that Date_assigned is a date/time field that is truncated to a date field.
Is there any other (more clean?/faster/more efficent) way to do a running sum in SQL Server??
Thanks
In Oracle you can use the sum() Partition by to create a running sum... or running count()... In SQL Server this doesnt seem possible....
What I have now:
Code:
Select country_code
, myDatum
, count(*) as CountOfDay
, ( select count(*)
from t_table i
where i.country_code = tni.country_code
and i.date_assigned < mydatum + 1 ) x
from (select *, cast( floor ( cast ( date_assigned as float ) ) as datetime) as mydatum
from t_table ) tni
where country_code = 'FR'
group by country_code, mydatum
order by mydatum
Is there any other (more clean?/faster/more efficent) way to do a running sum in SQL Server??
Thanks