![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
#12
| |||
| |||
|
|
Your sample data does not seem to correspond to the desired results. After cleaning your data and code a bit, commenting out the components that you did not provide (like the function and linked server), running the code results in this: doc *totovrs * * totpnds * * totovr * * *totpnd * * *weekdat dowrdat ---- ----------- ----------- ----------- ----------- ----------------------- ----------------------- 009 *0 * * * * * 6 * * * * * 0 * * * * * 0 * * * * * 2010-05-14 00:00:00.000 2010-05-28 00:00:00.000 200 *0 * * * * * 6 * * * * * 0 * * * * * 0 * * * * * 2010-05-14 00:00:00.000 2010-05-28 00:00:00.000 009 *0 * * * * * 0 * * * * * 0 * * * * * 6 * * * * * 2010-05-14 00:00:00.000 2010-05-28 00:00:00.000 200 *0 * * * * * 0 * * * * * 0 * * * * * 6 * * * * * 2010-05-14 00:00:00.000 2010-05-28 00:00:00.000 Not really sure how you need this data summarized. Here is just a guess. eliminate both insert queries into PendingDiary and use the following insert query: INSERT INTO PendingDiary (doc, totovrs, totpnds, totovr, totpnd, weekdat, dowrdat) SELECT doc, * * * *COUNT(CASE WHEN clear = 'O' AND SDW = 'Y' THEN doc END) AS totovrs, * * * *COUNT(CASE WHEN SDW = 'Y' THEN doc END) AS totpnds, * * * *COUNT(CASE WHEN clear = 'O' AND SDW = 'N' THEN doc END) AS totovr, * * * *COUNT(CASE WHEN SDW = 'Y' THEN doc END) AS totopnd, * * * *weekdat, * * * *dowrdat FROM #temppend WHERE SDW IN ('Y', 'N') GROUP BY doc, weekdat, dowrdat; This results in the following summarized data: doc *totovrs * * totpnds * * totovr * * *totpnd * * *weekdat dowrdat ---- ----------- ----------- ----------- ----------- ----------------------- ----------------------- 009 *0 * * * * * 6 * * * * * 0 * * * * * 6 * * * * * 2010-05-14 00:00:00.000 2010-05-28 00:00:00.000 200 *0 * * * * * 6 * * * * * 0 * * * * * 6 * * * * * 2010-05-14 00:00:00.000 2010-05-28 00:00:00.000 -- Plamen Ratchevhttp://www.SQLStudio.com |
![]() |
| Thread Tools | |
| Display Modes | |
| |