Grouping by 'trimmed' date

Posts   
 
    
Posts: 30
Joined: 08-Apr-2008
# Posted on: 07-Jul-2008 14:33:53   

Hi!

I've got a table containing logs and I would like to perform some aggregate functions with a group by that trims the date.

Here's the SQL equivalent of what I want:

select convert(datetime, cast(datepart(day,viewed_on) as varchar) + '.' + cast(datepart(month,viewed_on) as varchar) + '.' + cast(datepart(year,viewed_on) as varchar), 104) as trimmed_date, sum(id)
from
employer_view;

Cheers, Nitin

PS: The trimmed date sets the hour and minute to 0.

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 07-Jul-2008 14:48:08   

Use a dynamicList, with DBFunctionCall expression applied to the required field, to implement the convert function.

Then use the same field in a groupby clause.

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 07-Jul-2008 14:51:48   

I'd use the following expression on a Resultset field (e.g. ConsolidationValue) in a dynamic typed list :

fields("ConsolidationValue").ExpressionToApply = New DbFunctionCall("CAST(FLOOR(CAST({0} AS FLOAT)) AS DATETIME)", New Object() {TransactionDetailFields.DateTransaction})

TransactionDetailFields.DateTransaction is a DateTime field in a table.

grtz, Danny