Hi,
I'm having a hard time to figure out the following. Suppose you have a table like this:
Employee | Sales | Month
1 | 500 | 1
1 | 200 | 2
1 | 100 | 3
1 | 300 | 4
2 | 100 | 1
2 | 400 | 2
Well, now you want to have a result set that contains (1) the sum of sales, (2) the maximum months and (3) the amount of included months for (a) an employee X and (b) a certain amount of months Y.
Example 1: (a) employee X= 1, (b) months Y<= 3
(1) Sum of Sales | (2) Max. Months | (3) Included Months
800 | 4 | 3
In the first Y==3 months emloyee X==1 has made (1) 800$, which is the sum of (3) 3 months of selling. All in all he has been selling products since (2) 4 months.
Example 2: (a) employee X= 2, (b) months Y<= 3
(1) Sum of Sales | (2) Max. Months | (3) Included Months
500 | 2 | 2
In the first Y==3 months emloyee X==2 has made (1) 500$, which is the sum of (3) 2 months of selling. All in all he has been selling products since (2) 2 months.
My Problem:
I'm not sure ho to solve this task with LLBL Gen.
First I tried to create a database view like
viewSales:
SELECT Employee, SUM(Sales) AS sumSales, MAX(Months) AS maxMonths
FROM Sales
GROUP BY Employee
and then I hoped to be able to use an IPredicateExpression like
viewSalesCollection sales = new viewSalesCollection();
IPredicateExpression filter = new PredicateExpression();
filter.AddWithAnd(viewSalesFields.employee == x);
filter.AddWithAnd(viewSalesFields.months <= y);
If I set x=1 and y=3 as in example no. 1, then I receive the following result (which is not what I'm looking for, see column (2) in red):
(1) Sum of Sales | (2) Max. Months | (3) Exisiting Months
800 | 3 | 3
The problem is the "month filter". I can not limit the months to 3 on the one hand, and on the other hand expect a (2) max. amount of months of 4.
I'm sure there is a way to solve this whole thing with LLBL, the question is just: HOW?
Could anybody please help me out on this? Thank you so much!
Ingmar