March 8, 2012 at 4:43 pm
Woo Hoo I figured it out!
SELECT b.number, b.cashdate, SUM(b.cashamt) FROM
(
SELECT c.number, c.cashdate, a.cashamt
FROM
(
SELECT number, MAX(cashdate) AS cashdate from arcashha
GROUP BY number
) AS c
INNER JOIN arcashha a ON c.number = a.number and c.cashdate = a.cashdate
GROUP BY c.number, c.cashdate, a.cashamt
) AS b
GROUP BY b.number, b.cashdate
ORDER BY number
March 8, 2012 at 4:46 pm
Wat were u trying to do actually?? is there a question here?
March 8, 2012 at 4:46 pm
Confused. Figured what out? If you figured something out regarding a question you asked, you really should post it in that thread.
March 8, 2012 at 6:56 pm
If you have multiple records with the same value of number, cashdate and cashamt
in your arcashha table, you will sum only one of that rows.
I believe this is not desired behaviour (bug) ?
Do you actually need to sum all cashamt that happened on last cashdate per each number?
March 9, 2012 at 2:04 pm
looks like this post is for this thread. http://www.sqlservercentral.com/Forums/Topic1263956-1292-1.aspx
however that query is hella ugly and really could be rewritten to work much faster as you are only working on one table. to really get it nice we would need nice sample data and the desired output.
For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]
Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
Jeff Moden's Cross tab and Pivots Part 1[/url]
Jeff Moden's Cross tab and Pivots Part 2[/url]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply