Walaa wrote:
This is what i am wanting. That sql was just for one column. I thought that one could speacify a expression per column
You can specify an expression per column/field. Using the ExpressionToApply property.
select product.name,groupstorerequest.datecreated as currentsales,space(20) as previoussales
from groupstoreorder
inner join groupstorerequest
on groupstorerequest.groupstoreorderid = groupstoreorder.groupstoreorderid
inner join product
on groupstorerequest.productid = product.productid
where datecreated between date and date
union
select product.name,space(20) as currentsales,groupstorerequest.datecreated as previoussales
from groupstoreorder
inner join groupstorerequest
on groupstorerequest.groupstoreorderid = groupstoreorder.groupstoreorderid
inner join product
on groupstorerequest.productid = product.productid
where datecreated between date2 and date2
It's not clear what's going wrong now with this code, so please explain.
Btw, we don't support Union.
Here is the answer.
public DataTable GetGroupStoreOrderActivityInfoDataTable(Guid? pGroupStoreId)
{
DataTable dataTable = new DataTable();
this.LLBLGenPattern.PerformTryCatch(
delegate(IDataAccessAdapter adapter)
{
// bucket
RelationPredicateBucket bucket = new RelationPredicateBucket();
// relations
bucket.Relations.Add(
GroupStoreOrderEntity.Relations.GroupStoreOrderRequestEntityUsingGroupStoreOrderId,
JoinHint.Left);
bucket.Relations.Add(GroupStoreOrderRequestEntity.Relations.ProductEntityUsingProductId,
JoinHint.Left);
bucket.Relations.Add(
GroupStoreOrderEntity.Relations.GroupStoreOrderActivationEntityUsingGroupStoreOrderId,
JoinHint.Left);
// filters
bucket.PredicateExpression.Add(GroupStoreOrderFields.IsActive == true);
if (pGroupStoreId != Guid.Empty)
bucket.PredicateExpression.Add(GroupStoreOrderFields.GroupStoreId == pGroupStoreId);
// sort
// fields
ResultsetFieldsHelper fields = new ResultsetFieldsHelper();
fields.DefineField(GroupStoreOrderFields.GroupStoreId);
fields.DefineField(GroupStoreOrderRequestFields.ProductId);
fields.DefineField(ProductFields.Name);
**
IPredicateExpression Current = new PredicateExpression();
Current.Add(GroupStoreOrderRequestFields.DateCreated >= DateTime.Parse(DateTime.Now.ToString("yyyy/MM") + "/01 00:00:00.001"));
Current.AddWithAnd(GroupStoreOrderRequestFields.DateCreated <= DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM") + "/01 23:59:59.001").AddDays(-1));**
fields.DefineField(new EntityField2("Current",
new ScalarQueryExpression(
GroupStoreOrderRequestFields.DateCreated.SetAggregateFunction
(AggregateFunction.Count),
(Current))), "Current");
** IPredicateExpression Previous = new PredicateExpression();
Previous.Add(GroupStoreOrderRequestFields.DateCreated >= DateTime.Parse(DateTime.Now.AddMonths(-1).ToString("yyyy/MM") + "/01 00:00:00.001"));
Previous.AddWithAnd(GroupStoreOrderRequestFields.DateCreated <= DateTime.Parse(DateTime.Now.ToString("yyyy/MM") + "/01 23:59:59.001").AddDays(-1));**
fields.DefineField(new EntityField2("Previous",
new ScalarQueryExpression(
GroupStoreOrderRequestFields.DateCreated.SetAggregateFunction
(AggregateFunction.Count),
(Previous))), "Previous");
//GROUP BY
IGroupByCollection groupByClause = new GroupByCollection();
groupByClause.Add(GroupStoreOrderFields.GroupStoreId);
groupByClause.Add(GroupStoreOrderRequestFields.ProductId);
groupByClause.Add(ProductFields.Name);
//HAVING
//groupByClause.HavingClause = new PredicateExpression(
// GroupStoreOrderRequestFields.Quantity > 10
// );
adapter.FetchTypedList(fields.ToResultsetFields(), dataTable, bucket, 0, null, false, groupByClause);
}
);
return dataTable;
}