I am trying to group records based on the id - it works fine until I need additional filters such as date. How can I group the records and also display other information. I included a screenshot to show how it is not displaying correctly - for example I would like the name Marketing to only display once.
Any help is appreciated
SELECT leadervotes.voteid, SUM(DISTINCT leadervotes.votelevel) AS Expr1, leadervotes.votedate, nominations.astname
FROM leadervotes INNER JOIN
nominations ON leadervotes.voteid = nominations.recordid
GROUP BY leadervotes.voteid, leadervotes.votedate, nominations.astname
HAVING (leadervotes.votedate > CONVERT(DATETIME, '2013-07-31 00:00:00', 102))
ORDER BY leadervotes.voteid DESC
Essentially by using subqueries. Looking at 2137 above, I see two values for votedate, so you'll have to spell out the logic behind which one you want to display.
An excellent idea would be for you to mock up how you wish the return set to look, given the source data in the image.
>for example I would like the name Marketing to only display once.
If your requirements end up dictating that you would have two 2137 rows with the value 'Marketing', better to leave the values in the set, and let SSRS or whatever report tool you are using suppress duplicate values.