| Author |
Topic |
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-18 : 09:48:35
|
I want to add the totpnd column to have one column appearing as the results. I tried this but it didn't work what am I missing/doing wrong?SELECT doc, totovrs, totpnds, totovr, SUM(totpnd) AS totpnd, weekdat, dowrdatFROM PendingdiaryWHERE (doc = '207')GROUP BY doc, totovrs, totpnds, totovr, totpnd, weekdat, dowrdatDoc Totovrs Totpnds Totovr Totpnd 207 0 0 5 2207 0 0 5 1207 0 0 5 1207 0 0 5 1207 0 0 5 2207 0 0 5 1 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-05-18 : 10:04:35
|
Remove totpnd from the GROUP BYSELECT doc, totovrs, totpnds, totovr, SUM(totpnd) AS totpnd, weekdat, dowrdatFROM PendingdiaryWHERE (doc = '207')GROUP BY doc, totovrs, totpnds, totovr, weekdat, dowrdat |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-18 : 10:04:38
|
| Never mind I got it:SELECT doc, totovrs, totpnds, totovr, SUM(totpnd) AS totpndFROM PendingdiaryWHERE (doc = '207')GROUP BY doc, totovrs, totpnds, totovr |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-18 : 10:33:51
|
I'm back again.How would I get this statement to work:Update PendingDiarySELECT doc, totovrs, totpnds, totovr, SUM(totpnd) AS totpndFROM PendingdiaryGROUP BY doc, totovrs, totpnds, totovr My problem is I've inherited a website but the programmer has retired. She wrote this stored procedure which works but it's not adding the totpnd column. So I created this which works well:SELECT doc, totovrs, totpnds, totovr, SUM(totpnd) AS totpndFROM PendingdiaryGROUP BY doc, totovrs, totpnds, totovr Only thing it doesn't update the PendingDiary Table. I wanted to add the above line of code to the bottom of the store procedure. Here's the complicated stored procedure:truncate table PendingDiaryinsert into PendingDiarySelect b.doc, isnull(totos,0) as totovrs, isnull(totps,0) as totpnds, isnull(toto,0) as totovr, isnull(totp,0) as totpnd, b.weekdat, b.dowrdat From (select doc, count(doc) as totos, toto = '0' from #temppendwhere clear = 'O' and SDW = 'Y' group by doc )a right join (select doc, count(doc) as totps, totp = '0', weekdat, dowrdat from #temppend where SDW = 'Y' group by doc,weekdat, dowrdat )bon b.doc = a.docinsert into PendingDiary Select d.doc, isnull(totos,0) as totovrs, isnull(totps,0) as totpnds, isnull(toto,0) as totovr, isnull(totp,0) as totpnd, d.weekdat, d.dowrdat from(select doc, totos = '0', count(doc) as totofrom #temppendwhere clear = 'O' and SDW = 'N' group by doc)cright join(select doc, totps = '0', count(doc) as totp, weekdat, dowrdat from #temppendwhere SDW = 'N'group by doc, weekdat, dowrdat )don d.doc = c.docUpdate PendingDiary set dowrdat=offices.dbo.endofmonth(weekdat) where dowrdat is nulldrop table #temppend Or if you know where I can total the column in this procedure I'll add it there. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-05-18 : 10:37:23
|
Is this your desired resulkt after the update?Doc Totovrs Totpnds Totovr Totpnd 207 0 0 5 8207 0 0 5 8207 0 0 5 8207 0 0 5 8207 0 0 5 8207 0 0 5 8 |
 |
|
|
JJ297
Aged Yak Warrior
940 Posts |
Posted - 2010-05-18 : 11:23:44
|
No here's some data. That big stored procedure produces this which is okay but it's not adding the Totpnd column. Doc Totovrs Totpnds Totovr Totpnd weekdat dowrdat 020 0 0 5 2 5/14/2010 5/28/2010 020 0 0 5 6 5/14/2010 5/28/2010 207 0 0 5 1 5/14/2010 5/28/2010207 0 0 5 1 5/14/2010 5/28/2010 207 0 0 5 4 5/14/2010 5/28/2010 207 0 0 5 2 5/14/2010 5/28/2010 007 0 0 5 2 5/14/2010 5/28/2010 007 0 0 5 4 5/14/2010 5/28/2010 007 0 0 5 1 5/14/2010 5/28/2010008 0 0 5 1 5/14/2010 5/28/2010 008 0 0 5 3 5/14/2010 5/28/2010 008 0 0 5 6 5/14/2010 5/28/2010 I would like to have this outcome instead where only one doc is shown and the grand total is in the Totpnd columnDoc Totovrs Totpnds Totovr Totpnd weekdat dowrdat020 0 0 5 8 5/14/2010 5/28/2010 207 0 0 5 8 5/14/2010 5/28/2010007 0 0 5 7 5/14/2010 5/28/2010 008 0 0 5 10 5/14/2010 5/28/2010 I hope that makes sense. |
 |
|
|
|
|
|