I have a table with a datefield in it.
create TABLE FTAF(FtafID int IDENTITY(1,1) NOT NULL, SentDate datetime)
I wish to do this query.
select count(sentdate) as count, max(sentdate) as date,
datename(month,sentdate) as month, datename(year,sentdate) as year
from ftaf f
group by datename(month,sentdate), datename(year,sentdate)
order by date asc
My LLBLGEN code looks like this. (I'm using a custom FunctionExpression that lets me do the dateName function) (Self Servicing model)
ResultsetFields fields = new ResultsetFields(3);
fields.DefineField(FtafFieldIndex.SentDate, 0, "count",string.Empty,AggregateFunction.Count);
fields.DefineField(FtafFieldIndex.SentDate, 1, "month");
fields.DefineField(FtafFieldIndex.SentDate, 2, "year");
fields["month"].ExpressionToApply = new FunctionExpression(EntityFieldFactory.Create(FtafFieldIndex.SentDate), "datename", "month,");
fields["year"].ExpressionToApply = new FunctionExpression(EntityFieldFactory.Create(FtafFieldIndex.SentDate), "datename", "year,");
IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(fields["month"]);
groupByClause.Add(fields["year"]);
DataTable dt = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, dt, 0, null, null, null, false, groupByClause, null, 0, 0);
this.grdStats.DataSource = dt;
this.grdStats.DataBind();
LLBLGEN gives me this
SELECT COUNT([dbo].[FTAF].[SentDate]) AS [count],
datename(month,[dbo].[FTAF].[SentDate]) AS [month],
datename(year,[dbo].[FTAF].[SentDate]) AS [year]
FROM [dbo].[FTAF]
GROUP BY [dbo].[FTAF].[SentDate],[dbo].[FTAF].[SentDate]
The problem is with the Group By. I need to get this
group by datename(month,sentdate), datename(year,sentdate)
but LLBLGEN gives me this.
GROUP BY [dbo].[FTAF].[SentDate], [dbo].[FTAF].[SentDate]
Obviously, I need to add the expression as the group by, but I'm not sure how to go about this... Anyone have any thoughts?