| Author |
Topic |
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-24 : 23:40:41
|
Hi all. I have probs on grouping by...Sample data...table - hrEmpPayrollSummaryempno period1 period2 pagibig_share1 1/1/2007 1/15/2007 20001 1/16/2007 1/30/2007 50001 2/1/2007 2/16/2007 60002 1/1/2007 1/15/2007 80003 1/16/2007 1/28/2007 90003 12/1/2007 1/15/2007 100003 12/1/2007 12/15/2007 10000expected result...result for the year 2007empno january february march april may june july august september october november december1 7000 6000 0 0 0 0 0 0 0 0 0 02 8000 0 0 0 0 0 0 0 0 0 0 0 3 9000 0 0 0 0 0 0 0 0 0 0 10000-Thanks-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-24 : 23:44:29
|
what happen when you have cross over month ?like4 1/1/2007 3/15/2007 10000 does the 10000 appear under Jan, Feb & March ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-24 : 23:45:57
|
| that will not happen. my front-end controls the passing of dates programatically.-thanks-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-24 : 23:55:55
|
quote: Originally posted by cwtriguns2002 that will not happen. my front-end controls the passing of dates programatically.-thanks-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet."
How about this ?3 12/1/2007 1/15/2007 10000 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-24 : 23:58:40
|
| still will not happen.-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-25 : 00:05:22
|
can you explain what is period1 and period2 for ? For this line of sample data you posted, period1 is greater than period2.3 12/1/2007 1/15/2007 10000 The summary by month is it going to take period2 into consideration ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-25 : 00:16:20
|
| oppps very sorry. it should be 3 12/1/2007 12/15/2007 10000period1 and period2 is a payroll period. They must fall in the same month/year as my default. -Thanks-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-25 : 00:19:15
|
[code]SELECT p.empno, jan = SUM(CASE WHEN MONTH(period1) = 1 THEN pagibig_share ELSE 0 END), feb = SUM(CASE WHEN MONTH(period1) = 2 THEN pagibig_share ELSE 0 END), mar = SUM(CASE WHEN MONTH(period1) = 3 THEN pagibig_share ELSE 0 END), . . .FROM hrEmpPayrollSummary pGROUP BY p.empno[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-25 : 00:20:00
|
| I donno what is the difference b/w period 1 and period 2i considered only period 1declare @t table (empno int, period1 datetime, period2 datetime, pagibig_share int)Insert @tSelect 1, '1/1/2007', '1/15/2007', 2000 union allSelect 1, '1/16/2007', '1/30/2007', 5000 union allSelect 1, '2/1/2007', '2/16/2007', 6000 union allSelect 2, '1/1/2007', '1/15/2007', 8000 union allSelect 3, '1/16/2007', '1/28/2007', 9000 union allSelect 3, '12/1/2007', '1/15/2007', 10000Select Empno, Isnull(Sum(Case when month(period1) = 1 Then pagibig_share End),0) as 'January', Isnull(Sum(Case when month(period1) = 2 Then pagibig_share End),0) as 'February', Isnull(Sum(Case when month(period1) = 3 Then pagibig_share End),0) as 'March', Isnull(Sum(Case when month(period1) = 4 Then pagibig_share End),0) as 'April', Isnull(Sum(Case when month(period1) = 5 Then pagibig_share End),0) as 'May', Isnull(Sum(Case when month(period1) = 6 Then pagibig_share End),0) as 'June', Isnull(Sum(Case when month(period1) = 7 Then pagibig_share End),0) as 'July', Isnull(Sum(Case when month(period1) = 8 Then pagibig_share End),0) as 'August', Isnull(Sum(Case when month(period1) = 9 Then pagibig_share End),0) as 'September', Isnull(Sum(Case when month(period1) = 10 Then pagibig_share End),0) as 'October', Isnull(Sum(Case when month(period1) = 11 Then pagibig_share End),0) as 'November', Isnull(Sum(Case when month(period1) = 12 Then pagibig_share End),0) as 'December' From @t Group by empno--------------------------------------------------S.Ahamed |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-25 : 01:42:41
|
| thanks sirs-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-25 : 03:19:25
|
| Also if you use reports to show data, you can make use of its Cross tab featureMadhivananFailing to plan is Planning to fail |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-25 : 03:25:15
|
| yes i am showing the data in report... whats this cross tabs?-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-25 : 04:44:09
|
| Which report are you using?MadhivananFailing to plan is Planning to fail |
 |
|
|
cwtriguns2002
Constraint Violating Yak Guru
272 Posts |
Posted - 2007-06-25 : 21:11:36
|
| reporting services...-Ron-"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet." |
 |
|
|
|